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

可以到这里来找资料:discuz资料库

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

source\plugin

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

config\config_global.php文件中写入

$_config['plugindeveloper'] = 1;

还要清楚插件的唯一标识符

122144_82RI_2294923.png

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

在调用的时候可以用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);

122954_5NF0_2294923.jpg

做缓存举例

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');


转载于:https://my.oschina.net/u/2294923/blog/667462

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值