ThinkPHP unlimited classification principle to implement the message and reply function instance, thinkphp instance
The message board program described in this article uses the principle of unlimited classification to enable unlimited messages and replies. The message list gclist retains spaces at the message level, so that the message-reply level is distinct. Share it with you for your reference. The specific analysis is as follows:
Function, this program can provide unlimited messages and replies, that is, reply to messages and reply to messages. Of course, you can also make limited control to only reply to messages. The key is to remove "reply to this message" from the reply message in the template code. Welcome to shoot bricks!
Shows the program effect:
Click here to download the complete source code.
Data Table:
Copy codeThe 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 codeThe Code is 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 a url in the form url, click it to jump to the relevant website.
// + ----------------------------------------------------------------------
Public function tourl (){
$ This-> gettourl ('guestbook ');
}
}
?>
<? Php
// + ----------------------------------------------------------------------
// | WBlog
// + ----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.w3note.com All rights reserved.
// | Author: Net pineapple fruit
// + ----------------------------------------------------------------------
// $ Id $
/**
+ ------------------------------------------------------------------------------
* @ Function the message board model class GuestbookModel. class. php
+ ------------------------------------------------------------------------------
*/
Class GuestbookModel extends RelationModel {
// + ----------------------------------------------------------------------
// | $ _ Validate form Automatic Verification
// + ----------------------------------------------------------------------
Protected $ _ validate = array (
Array ('email ', 'require', 'enter your email address! '),
Array ('email ', 'email', 'mailbox format error! '),
);
// + ----------------------------------------------------------------------
// | $ _ Auto form auto Filling
// + ----------------------------------------------------------------------
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 Username
// + ----------------------------------------------------------------------
Public function getusername (){
If (isset ($ _ POST ['username']) {
If (trim ($ _ POST ['username']) = 'net pineapple go '){
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. 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 the message content
// + ----------------------------------------------------------------------
Public function content (){
If (isset ($ _ POST ['content']) &! Empty ($ _ POST ['content']) {
$ Data = deleteHtmlTags ($ _ POST ['content']);
$ Data = safeHtml ($ data );
If (strlen ($ data) & gt; 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 condition, empty by default
// + ----------------------------------------------------------------------
// | $ Pagesize paging record. The default value is 30.
// + ----------------------------------------------------------------------
// | Usage. 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', 'topic ');
$ P-> setConfig ('prev ',"«");
$ P-> setConfig ('Next ','»');
$ P-> setConfig ('first', '| «');
$ P-> setConfig ('last', '» | ');
$ Page = $ P-> show ();
$ Arr = array ('page' => $ page, 'LIST' => $ list );
Return $ arr;
}
}
?>
I hope this article will help you with ThinkPHP framework programming.
The php Message Board provides unlimited replies.
I personally think it is okay to create a special database table. I will reply to each id and write the reply corresponding to this id to the table after each reply!
Reply content table:
Reply Id reply content
Reply to join table:
Reply content id reply Content id
In this way, you can implement unlimited replies!
Php + mysql three-level classification, Li Wenkai thinkphp unlimited Classification
So, what do you want to ask? Well, I have watched this video,