在模型类中编写查询方法,在控制器中调用模型中的方法即可。
// 实例化模型类
C::t('文件名')
Discuz 中的模型文件放在/source/class/table目录下
模型文件名由”table_表名“组成
编写模型文件类
// 安全验证
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
// 表类
class table_common_admincp_cmenu extends discuz_table
{
public function __construct() {
// 表名
$this->_table = 'common_admincp_cmenu';
// 主键名
$this->_pk = 'id';
// 调用父类方法
parent::__construct();
}
}
在source/class/table下建立以table_为前缀的php文件
构造模型类
if(!defined('IN_DISCUZ')) exit('Access Denied');
class table_xxx extends discuz_table{
public function __construct(){
$this->_table = ''; //表名
$this->_pk = ''; //主键名
parent::__construct();
}}
编写查询方法
在控制器中用C::t('文件名')来实例化模型类,->执行方法