Discuz!X 插件开发之在插件中使用自定义封装C::t查询
前提:
开启插件开发模式(自行搜索教程)。
假设我们的插件叫
Test,那么他的开发路径是:
\source\plugin\Test\,
Test就是你要开发的插件的存放目录。
我们在
Test插件目录下新建一个文件夹
table,看起来像这样:\source\plugin\
Test\
table\。
在table文件夹下新建php文件,重点来了,这个php文件的命名规则为
table_XXX.php。其中XXX这个建议不要跟默认的table名冲突。(有一定的几率导致查询失败。)
然后,我们在
table_XXX.php文件中写入以下代码:
- <?php
- if (!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- class table_XXX extends discuz_table
- {
- public function __construct() {
- $this->_table = '数据表';
- $this->_pk = '数据表主键';
- parent::__construct();
- }
- public function XXXA()
- {
- return DB::fetch_all("SELECT查询语句", array($this->_table), $this->_pk);
- }
- }
复制代码
代码解释: