찾다
php教程php手册ThinkPHP无限级分类原理实现留言与回复功能实例

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

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

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

程序效果如下图所示:

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

数据表:

复制代码 代码如下:

-- ----------------------------    
-- 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;

代码:

复制代码 代码如下:

// +----------------------------------------------------------------------    
// | WBlog    
// +----------------------------------------------------------------------    
// | Copyright (c) 2008  All rights reserved.    
// +----------------------------------------------------------------------    
// | Author: 网菠萝果    
// +----------------------------------------------------------------------    
// $Id$    
/**    
 +------------------------------------------------------------------------------    
 * @class 留言板控制器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   All rights reserved.    
// | Author: 网菠萝果    
// +----------------------------------------------------------------------    
// $Id$    
/**    
 +------------------------------------------------------------------------------    
 * @function 留言板模型 类GuestbookModel.class.php   
 +------------------------------------------------------------------------------    
 */
         
class GuestbookModel extends RelationModel{    
// +----------------------------------------------------------------------    
// | $_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()过滤用户名    
// +----------------------------------------------------------------------            
      public function getusername(){    
          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    
// +----------------------------------------------------------------------      
     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                     $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框架程序设计有所帮助。

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

SublimeText3 영어 버전

SublimeText3 영어 버전

권장 사항: Win 버전, 코드 프롬프트 지원!

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기