配色: 字号:
ThinkPHP无限级分类原理实现留言与回复功能实例
2016-11-02 | 阅:  转:  |  分享 
  
ThinkPHP无限级分类原理实现留言与回复功能实例



这篇文章主要介绍了ThinkPHP无限级分类原理实现留言与回复功能实例,并附带有完整的项目源码下载供大家学习参考,非常具有实用价值,需要的朋友可以参考下



本文所述留言板程序使用了无限级分类的原理,可以实现无限级留言与回复。留言列表gclist保留了留言层次空格,使留言--回复层次分明。分享给大家供大家参考。具体分析如下:



功能上,本程序可以实现无限级留言与回复,即对留言回复,对回复的留言回复。当然你也可以作有限制的控制,使其只对留言回复,关键是在模板代码中去掉回复的留言中的“回复该留言”即可。欢迎去拍砖!



完整源码点击此处本站下载。



数据表:





复制代码代码如下:



------------------------------

--Tablestructurefor`wb_guestbook`

------------------------------

DROPTABLEIFEXISTS`wb_guestbook`;

CREATETABLE`eway_guestbook`(

`id`int(10)unsignedNOTNULLAUTO_INCREMENT,

`pid`int(10)NOTNULL,

`email`varchar(50)NOTNULL,

`path`varchar(100)NOTNULL,

`username`varchar(30)NOTNULL,

`updatetime`int(10)NOTNULL,

`ip`varchar(15)NOTNULL,

`url`varchar(200)NOTNULL,

`inputtime`int(10)NOTNULL,

`content`textNOTNULL,

`verify`varchar(32)NOTNULL,

`isreply`tinyint(1)NOTNULL,

`status`tinyint(1)NOTNULL,

PRIMARYKEY(`id`)

)ENGINE=MyISAMAUTO_INCREMENT=42DEFAULTCHARSET=utf8;





代码:





复制代码代码如下:




//+----------------------------------------------------------------------

//|WBlog

//+----------------------------------------------------------------------

//|Copyright(c)2008http://www.w3note.comAllrightsreserved.

//+----------------------------------------------------------------------

//|Author:网菠萝果

//+----------------------------------------------------------------------

//$Id$

/

+------------------------------------------------------------------------------

@class留言板控制器GuestbookAction.class.php

+------------------------------------------------------------------------------

/

classGuestbookActionextendsCommonAction{

publicfunctionindex(){

$garr=D(''Guestbook'')->gclist("id,username,inputtime,pid,url,content,path,concat(path,''-'',id)asbpath");



$this->assign(''Gklist'',$garr[''list'']);

$this->assign(''page'',$garr[''page'']);

$this->display();

}

//+----------------------------------------------------------------------

//|添加留言

//+----------------------------------------------------------------------



publicfunctionadd(www.visa158.com){

$this->adddata(''Guestbook'');



}

//+----------------------------------------------------------------------

//|网址跳转。如在表单url添加网址的话,点击会跳转到相关网站

//+----------------------------------------------------------------------



publicfunctiontourl(){

$this->gettourl(''Guestbook'');

}

}

?>


//+----------------------------------------------------------------------

//|WBlog

//+----------------------------------------------------------------------

//|Copyright(c)2008http://www.w3note.comAllrightsreserved.

//|Author:网菠萝果

//+----------------------------------------------------------------------

//$Id$

/

+------------------------------------------------------------------------------

@function留言板模型类GuestbookModel.class.php

+------------------------------------------------------------------------------

/



classGuestbookModelextendsRelationModel{

//+----------------------------------------------------------------------

//|$_validate表单自动验证

//+----------------------------------------------------------------------



protected$_validate=array(

array(''email'',''require'',''请填写您的邮箱!''),

array(''email'',''email'',''邮箱格式错误!''),



);

//+----------------------------------------------------------------------

//|$_auto表单自动填充

//+----------------------------------------------------------------------



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()过滤用户名

//+----------------------------------------------------------------------

publicfunctiongetusername(){

if(isset($_POST[''username''])){

if(trim($_POST[''username''])==''网菠萝果''){

return$data='' ̄□ ̄'';

}elseif(strlen($_POST[''username''])>10){

return$data=msubstr($_POST[''username''],0,5);

}else{

return$data=$_POST[''username''];

}

}

}

//+----------------------------------------------------------------------

//|path()返回子类的path,父类的path的值为0

//+----------------------------------------------------------------------

publicfunctionpath(){

$pid=isset($_POST[''pid''])?(int)$_POST[''pid'']:0;

$id=$_POST[''id''];

if($pid==0){

return0;

}



$fat=$this->where(array(''id''=>$pid))->find();

$data=$fat[''path''].''-''.$fat[''id''];

return$data;

}

//+----------------------------------------------------------------------

//|content()过滤留言内容

//+----------------------------------------------------------------------

publicfunctioncontent(www.hunanwang.net){

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

//+----------------------------------------------------------------------

publicfunctiongeturl(){

if(isset($_POST[''url''])){

$data=deleteHtmlTags($_POST[''url'']);

$data=safeHtml($data);

return$data=$data?$data:"";

}

}

//+----------------------------------------------------------------------

//|gclist($field,$where='''',$pagesize=30)留言列表

//+----------------------------------------------------------------------

//|$field,字段

//+----------------------------------------------------------------------

//|$where查询条件,默认为空

//+----------------------------------------------------------------------

//|$pagesize分页记录,默认为30

//+----------------------------------------------------------------------

//|使用方法,看上面的控制器调用

//+----------------------------------------------------------------------



publicfunctiongclist($field,$where='''',$pagesize=30){

import("ORG.Util.Page");

$count=$this->field(''id'')->where($where)->count();

$P=newPage($count,$pagesize);



$list=$this->field($field)->where($where)->order(''bpath,id'')->limit($P->firstRow.'',''.$P->listRows)->select();



foreach($listas$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框架程序设计有所帮助。





















献花(0)
+1
(本文系白狐一梦首藏)