Discuz!X3.1程序练习
步骤一:建立数据表
步骤二:建立插件前台功能模块
步骤三:编写流程控制代码
步骤四:编写数据库提交表单
步骤五:编写数据库操作语句
步骤六:提示成功信息
控制器文件inc.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php error_reporting(7); if(!submitcheck('submit')){ include template('licai:forum/licaiapp'); }else{ //接收用户信息 if(!$_G['uid']){ showmessage('请先登录','member.php?mod=logging&action=login'); } if(empty($_GET['user'])){//empty判断接收到用户名是否存在 showmessage('请填写用户名'); } $id = C::t('#licai#test_db')->add_name($_GET['user']); if($id){ showmessage('用户贴加成功','forum.php'); } } ?> |
模型文件table_数据表名.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | <?php //防止程序跳过主程序执行判断 if(!defined('IN_DISCUZ')) { exit('Access Denied'); } class table_test_db extends discuz_table{ public function __construct() { $this->_table = 'test_db';//数据库表名称 $this->_pk = 'dId';//数据表主键名称 //$this->_pre_cache_key = 'test_db_';//数据缓存 parent::__construct(); } //插入数据 public function add_name($name){ return $this->insert(array( 'dname'=>$name )); } //更新数据 public function change_name_by_id($dId,$name){ $this->update($dId,array( 'dName' => $name, )); } //删除数据 public function delete_by_id($dId){ $this->delete($dId); } //取数据区间 public function get_last_name(){ return $this -> range(0,5,'DESC'); } } ?> |
视图文件.htm
1 2 3 4 5 6 7 | <!--{template common/header}--> <form action="plugin.php?id=licai:licaiapp" method="post"> 用户名:<input type="text" name="user" value=""/><br/> <input type="hidden" name="formhash" value="{FORMHASH}"/> <input type="submit" name="submit" value="提交"/> </form> <!--{template common/footer}--> |