discuz插件的编写方法(全网惟一详细解说)

能够到这里来找资料:discuz资料库php

首先要知道放插件的目录是啥
缓存

source\pluginui

还要知道如何在后台开启插件编写模式,即在
this

config\config_global.php文件中写入插件

$_config['plugindeveloper'] = 1;debug

还要清楚插件的惟一标识符code

还要懂discuz的一些游戏规则:一、全部表都写一个类,放在table文件夹中,而且名称和表名一致。全部的这些类都要继承基类如class table_test_db extends discuz_tablehtm

在调用的时候能够用C::t()方法。注意t()方法实际的做用是返回所调表所在操做类后实例化对象,这样就能够调用操做该表的类中的方法了,挺绕了!对象

有了这些基础你就能够玩插件了。继承

给出参考

<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_test_db extends discuz_table{
    public function __construct() {
$this->_table = 'test_db';
$this->_pk    = 'id';
parent::__construct();
}
        public function test(){
            echo 'phpchina';
        }
}
<?php
    $data = C::t('#ppctest#test_db')->test();
    debug($data);

作缓存举例

if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_common_member extends discuz_table_archive
{
public function __construct() {
$this->_table = 'common_member';
$this->_pk    = 'uid';
$this->_pre_cache_key = 'common_member_';
parent::__construct();
}

其中$this->_pre_cache_key = 'common_member_';就是缓存字段


插件写法抛砖事例:

<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_test_db extends discuz_table{
    public function __construct() {
$this->_table = 'test_db';
$this->_pk    = 'id';
parent::__construct();
}
        public function add_name($name){
           $this->insert(array(
               'name'=>$name,
           ));
        }
}

调用的写法

<?php
    C::t('#ppctest#test_db')->add_name('phpchina');
相关文章
相关标签/搜索