一、完善用户是否开启回贴通知
利用模型的方法,获取用户的设置状态
1、创立好数据库
create table 前缀_模块_逻辑表名 (
`uid` mediumint(8) unsigned NOT NULL,`isnotice` tinyint not null default 0 comment '0关闭,1开启',primary key (`uid`)
)engine=myisam charset=utf8;
在discuz目录/source/plugin/下创建以插件唯一标识为名字创建目录。
使用某个表,需要为表创建一个模型
每个模型也是一个类,继承自discuz核心模型discuz_table。
<?PHP
//判断是否被常规请求
defined('IN_DISCUZ') or die('Access Denied');
class table_forum_post_notice extends discuz_table {
//构造方法中,指明表,主键字段,和调用父类构造方法
public function __construct() {
$this->_table = 'forum_post_notice';
$this->_pk = 'uid';
parent::__construct();
}
}
if($_GET['pluginop'] == 'get') {
//获取插件下的某个模型
$mForumPostNotice = C::t('#post_notice#forum_post_notice');
//获取某用户的设置状态
$isNotice = $mForumPostNotice->getNoticeState($_G['uid']);
}
public function getNoticeState($uid = 0) {
if($uid == 0) return 0;
//使用discuz的dao类,discuz_database,完成数据库操作
//DB类继承自discuz_database类,在class_core.PHP文件中
$sql = "SELECT isnotice FROM `%t` WHERE `uid`=%d";
return intval(DB::result_first($sql,array($this->_table,$uid)));
}
即post_set.htm。
<div>
<form method="post" autocomplete="off" action="home.PHP?mod=spacecp&ac=plugin&id=post_notice:post_set&pluginop=set">
<p class="tbmu mbm">回贴通知</p>
<table cellspacing="0" cellpadding="0" class="tfm">
<tr>
<th>是否开启回贴通知:</th>
<td>
<input type="radio" name="isNotice" value="1" <!--{if $isNotice==1}-->checked<!--{/if}--> />开启
<input type="radio" name="isNotice" value="0" <!--{if $isNotice==0}-->checked<!--{/if}--> />关闭
</td>
</tr>
<tr>
<th> </th>
<td><button type="submit" name="privacysubmit" value="true" class="pn pnc" /><strong>{lang save}</strong></button></td>
</tr>
</table>
</form>
</div>