可以到这里来找资料:discuz资料库
首先要知道放插件的目录是啥
source\plugin
还要知道如何在后台开启插件编写模式,即在
config\config_global.php文件中写入
$_config['plugindeveloper'] = 1;
还要清楚插件的唯一标识符
还要懂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);
做缓存举例
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');