ThinkPHP infinite classification principle to implement message and reply function examples, thinkphp examples
The message board program described in this article uses the principle of unlimited classification, which can realize unlimited messages and replies. The message list gclist retains message hierarchical spaces to make messages and replies clearly hierarchical. Share it with everyone for your reference. The specific analysis is as follows:
Functionally, this program can achieve unlimited levels of messages and replies, that is, reply to messages and reply to messages in reply. Of course, you can also make limited control so that it can only reply to messages. The key is to remove "reply to this message" in the reply message in the template code. Welcome to Paizhuan!
The program effect is as shown below:
Click here to download the complete source code.
Data sheet:
Copy code The code is as follows:
-------------------- ---------
-- Table structure for `wb_guestbook`
-------------------------------
DROP TABLE IF EXISTS `wb_guestbook`;
CREATE TABLE `eway_guestbook` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`pid` int(10) NOT NULL,
`email` varchar(50) NOT NULL,
`path` varchar(100) NOT NULL,
`username` varchar(30) NOT NULL,
`updatetime` int(10) NOT NULL,
`ip` varchar(15) NOT NULL,
`url` varchar(200) NOT NULL,
`inputtime` int(10) NOT NULL,
`content` text NOT NULL,
`verify` varchar(32) NOT NULL,
`isreply` tinyint(1) NOT NULL,
`status` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARSET=utf8;
Code:
Copy code The code is as follows:
// +----------------------------------------------------------------------
// | WBlog
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.w3note.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 网菠萝果
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------- --------------------------------
* @class Message Board Controller GuestbookAction.class.php
+------------------------------------------------- --------------------------------
*/
class GuestbookAction extends CommonAction {
public function index(){
$garr= D('Guestbook')->gclist("id,username,inputtime,pid,url,content,path,concat(path,'-',id) as bpath");
$this->assign('Gklist', $garr['list']);
$this->assign('page',$garr['page']);
$this->display();
}
// +----------------------------------------------------------------------
// | 添加留言
// +----------------------------------------------------------------------
public function add(){
$this->adddata('Guestbook');
}
// +----------------------------------------------------------------------
// | 网址跳转。如在表单url添加网址的话,点击会跳转到相关网站
// +----------------------------------------------------------------------
public function tourl(){
$this->gettourl('Guestbook');
}
}
?>
// +----------------------------------------------------------------------
// | WBlog
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.w3note.com All rights reserved.
// | Author: 网菠萝果
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------- --------------------------------
* @function Message Board Model Class GuestbookModel.class.php
+------------------------------------------------- --------------------------------
*/
class GuestbookModel extends RelationModel{
// +----------------------------------------------------------------------
// | $_validate表单自动验证
// +----------------------------------------------------------------------
protected $_validate = array(
array ('email','require', 'Please fill in your email address!'),
Array ('email', 'email', 'email format error!'),
);
// +-------------------------------------------------- -----------------------
// | $_auto form autofill
// +-------------------------------------------------- -----------------------
protected $_auto=array(
array('status','1'),
array('inputtime','time',1,'function'),
array('content','content',1,'callback'),
array('url','geturl',1,'callback'),
array ('inputtime','time',1,'function'),
array('path','path',3,'callback'),
array('username','getusername',3,'callback'), array('username','getusername',3,'callback'),
);
// +-------------------------------------------------- -----------------------
// | getusername() filters usernames
// +-------------------------------------------------- -----------------------
Public function getusername(){
If (isset ($_POST['username'])) {
If (trim ($ _ post ['username'] == 'Net pineapple fruit') {
Return $ data = '□ □  ̄';
}elseif(strlen($_POST['username']) >10){
return $data= msubstr($_POST['username'],0,5);
return $data= $_POST['username'];
// +-------------------------------------------------- -----------------------
// | path() returns the path of the subclass, and the value of the path of the parent class is 0.
// +-------------------------------------------------- -----------------------
Public function path(){
$pid=isset($_POST['pid'])?(int)$_POST['pid']:0;
$id=$_POST['id'];
if($pid==0){
return 0;
}
$fat=$this->where(array('id' => $pid))->find();
$data=$fat['path'].'-'.$fat['id'];
return $data;
}
// +----------------------------------------------------------------------
// | content()过滤留言内容
// +----------------------------------------------------------------------
public function content() {
if (isset ($_POST['content']) && !empty ($_POST['content'])) {
$data =deleteHtmlTags($_POST['content']);
$data =safeHtml($data);
if (strlen($data) > 1000) {
$data = msubstr($data, 0, 500);
}
return $data;
}
}
// +----------------------------------------------------------------------
// | content()过滤URL
// +----------------------------------------------------------------------
public function geturl(){
if (isset ($_POST['url'])) {
$data = deleteHtmlTags($_POST['url']);
$data = safeHtml($data);
return $data=$data?$data:"";
}
}
// +----------------------------------------------------------------------
// |gclist($field,$where='',$pagesize=30)留言列表
// +----------------------------------------------------------------------
// |$field,字段
// +----------------------------------------------------------------------
// |$where查询条件,默认为空
// +----------------------------------------------------------------------
// |$pagesize分页记录,默认为30
// +----------------------------------------------------------------------
// |使用方法,看上面的控制器调用
// +----------------------------------------------------------------------
public function gclist($field,$where='',$pagesize=30) {
import("ORG.Util.Page");
$count = $this->field('id')->where($where)->count();
$P = new Page($count, $pagesize);
$list=$this->field($field)->where($where)->order('bpath,id')->limit($P->firstRow . ',' . $P->listRows)->select();
foreach ($list as $k => $v) {
$list[$k]['count'] = count(explode('-', $v['bpath']));
$list[$k]['tousername']=$this->where(array('id'=> $v['pid']))->getField('username');
$str = '';
if ($v['pid'] <> 0) {
for ($i = 0; $i < $list[$k]['count'] * 2; $i++) {
$str .= ' ';
}
$str .= ' ';
}
$list[$k]['space'] = $str;
}
$P->setConfig('header', '篇');
$P->setConfig('prev', "«");
$P->setConfig('next', '»');
$P->setConfig('first', '|«');
$P->setConfig('last', '»|');
$page = $P->show();
$arr=array('page'=>$page,'list'=>$list);
return $arr;
}
}
?>
希望本文所述对大家的ThinkPHP框架程序设计有所帮助。
个人觉得建立一个专门的数据库表就可以了,给每个回复一个id然后在每次有回复后将这个id对应的回复写入表中就ok了!
回复内容表:
回复Id 回复内容
回复关联表:
回复内容id 回复内容id
这样就可以实现无限回复了!
So, what do you want to ask?,,,, I have also watched this video, it’s pretty good,
http://www.bkjia.com/PHPjc/904009.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/904009.htmlTechArticleThinkPHP infinite level classification principle to realize the message and reply function example, thinkphp example The message board program described in this article uses infinite level The principle of classification can achieve unlimited levels of messages and replies. ...