In this paper, the message Board program uses the principle of infinite class classification, can realize the infinite level message and reply. Message list Gclist retained the message level space, so that message--the level of the reply clearly. Share to everyone for your reference. The specific analysis is as follows:
On the function, this procedure can realize the infinite level message and the reply, namely to the message reply, to reply the message reply. Of course, you can also make limited control, so that it only reply to the message, the key is in the template code to remove the reply to the message "Reply to this message" can be. Welcome to the Brick!
The program effect is shown in the following illustration:
Full source Click here to download the site.
Data table:
Copy Code code as follows:
-- ----------------------------
--Table structure for ' wb_guestbook '
-- ----------------------------
DROP TABLE IF EXISTS ' Wb_guestbook ';
CREATE TABLE ' Eway_guestbook ' (
' ID ' int (a) unsigned not NULL auto_increment,
' PID ' int (a) not NULL,
' Email ' varchar not NULL,
' Path ' varchar not NULL,
' username ' varchar not NULL,
' UpdateTime ' int (a) not NULL,
' IP ' varchar not NULL,
' url ' varchar not NULL,
' Inputtime ' int (a) not NULL,
' Content ' text not NULL,
' Verify ' varchar 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 code as follows:
<?php
// +----------------------------------------------------------------------
// | Wblog
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.w3note.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Net pineapple Fruit
// +----------------------------------------------------------------------
$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 ();
}
// +----------------------------------------------------------------------
// | Add a message
// +----------------------------------------------------------------------
Public function Add () {
$this->adddata (' guestbook ');
}
// +----------------------------------------------------------------------
// | URL jump. If you add URLs to the form URL, click to jump to the relevant site
// +----------------------------------------------------------------------
Public Function Tourl () {
$this->gettourl (' guestbook ');
}
}
?>
<?php
// +----------------------------------------------------------------------
// | Wblog
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.w3note.com All rights reserved.
// | Author: Net pineapple Fruit
// +----------------------------------------------------------------------
$Id $
/**
+------------------------------------------------------------------------------
* @function Message board model class GuestbookModel.class.php
+------------------------------------------------------------------------------
*/
Class Guestbookmodel extends relationmodel{
// +----------------------------------------------------------------------
// | $_validate Automatic verification of form forms
// +----------------------------------------------------------------------
Protected $_validate = Array (
Array (' email ', ' require ', ' please fill in your email! '),
Array (' email ', ' email ', ' mailbox format error!) '),
);
// +----------------------------------------------------------------------
// | $_auto Form Auto Fill
// +----------------------------------------------------------------------
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 '),
);
// +----------------------------------------------------------------------
// | GetUserName () filter User name
// +----------------------------------------------------------------------
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);
}else{
return $data = $_post[' username '];
}
}
}
// +----------------------------------------------------------------------
// | Path () returns the path of the subclass, and the path value 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 () filter message contents
// +----------------------------------------------------------------------
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 () Filter URL
// +----------------------------------------------------------------------
Public Function Geturl () {
if (isset ($_post[' url ')) {
$data = deletehtmltags ($_post[' url '));
$data = safehtml ($data);
return $data = $data $data: "";
}
}
// +----------------------------------------------------------------------
|gclist ($field, $where = ', $pagesize =30) message list
// +----------------------------------------------------------------------
| $field, Field
// +----------------------------------------------------------------------
| $where query criteria, default is NULL
// +----------------------------------------------------------------------
| $pagesize paging record, defaults to 30
// +----------------------------------------------------------------------
| Use the method to see the controller call above
// +----------------------------------------------------------------------
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 ', ' article ');
$P->setconfig (' prev ', "«");
$P->setconfig (' Next ', '» ');
$P->setconfig (' A ', ' |«');
$P->setconfig (' Last ', '»| ');
$page = $P->show ();
$arr =array (' page ' => $page, ' list ' => $list);
return $arr;
}
}
?>
I hope this article will be helpful to everyone's thinkphp framework program design.