boaPHP开发手册v5.5

数据模型

模型是一些常用的数据库表直接操作的封装类,为业务供给数据,便于维护和复用

定义

自定义模型位于每个模块下model目录中,例如:mod/home/model/test.php。不必一定要继承boa目录中的model文件,系统model文件往往起到一种演示作用


namespace mod\home\model;

use boa\model;

class test extends model{
	public function __construct(){
		parent::__construct(['table' => 'test']);
	}
	
	public function my_method($key, $num){
		$arr = $this->db->query('SELECT * FROM ...');
		foreach($arr as $k => $v){
			......
		}
		return $arr;
	}
}

使用

  • PHP中:
    
    $arr = boa::model('home.test')->my_method('hello world', 10);
    
  • 模板中:
    
    {$arr home.test.my_method 'hello world' 10} // 然后用list标签循环$arr