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

ThinkPHP无限级分类原理实现留言与回复功能实例

Jun 06, 2016 pm 08:18 PM
thinkphp Function reply message

这篇文章主要介绍了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框架程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Use ddrescue to recover data on Linux Use ddrescue to recover data on Linux Mar 20, 2024 pm 01:37 PM

DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

The difference between vivox100s and x100: performance comparison and function analysis The difference between vivox100s and x100: performance comparison and function analysis Mar 23, 2024 pm 10:27 PM

Both vivox100s and x100 mobile phones are representative models in vivo's mobile phone product line. They respectively represent vivo's high-end technology level in different time periods. Therefore, the two mobile phones have certain differences in design, performance and functions. This article will conduct a detailed comparison between these two mobile phones in terms of performance comparison and function analysis to help consumers better choose the mobile phone that suits them. First, let’s look at the performance comparison between vivox100s and x100. vivox100s is equipped with the latest

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

What exactly is self-media? What are its main features and functions? What exactly is self-media? What are its main features and functions? Mar 21, 2024 pm 08:21 PM

With the rapid development of the Internet, the concept of self-media has become deeply rooted in people's hearts. So, what exactly is self-media? What are its main features and functions? Next, we will explore these issues one by one. 1. What exactly is self-media? We-media, as the name suggests, means you are the media. It refers to an information carrier through which individuals or teams can independently create, edit, publish and disseminate content through the Internet platform. Different from traditional media, such as newspapers, television, radio, etc., self-media is more interactive and personalized, allowing everyone to become a producer and disseminator of information. 2. What are the main features and functions of self-media? 1. Low threshold: The rise of self-media has lowered the threshold for entering the media industry. Cumbersome equipment and professional teams are no longer needed.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

The original comment was deleted. Is the reply still there? Can others still see my comments after I delete them? The original comment was deleted. Is the reply still there? Can others still see my comments after I delete them? Mar 23, 2024 pm 05:56 PM

In a world where social media is overflowing with information, people are paying more and more attention to the content they post on the platform and how they interact with others. When we leave a comment under a certain post, if the original author deletes it, whether the comment will continue to exist has become a hotly debated issue. 1. The original comment has been deleted. Is the reply still there? First, it needs to be clear that social media platforms are highly flexible in how they handle user information and interactions. Even though the original comment is deleted, replies often remain below the post, even though they may not appear to be directly connected. This means that even if the original comment has disappeared, subsequent readers can still see the replies and infer some information based on those replies. Therefore, deleting the original comment will not completely eliminate traces of the interaction.

What are the functions of Xiaohongshu account management software? How to operate a Xiaohongshu account? What are the functions of Xiaohongshu account management software? How to operate a Xiaohongshu account? Mar 21, 2024 pm 04:16 PM

As Xiaohongshu becomes popular among young people, more and more people are beginning to use this platform to share various aspects of their experiences and life insights. How to effectively manage multiple Xiaohongshu accounts has become a key issue. In this article, we will discuss some of the features of Xiaohongshu account management software and explore how to better manage your Xiaohongshu account. As social media grows, many people find themselves needing to manage multiple social accounts. This is also a challenge for Xiaohongshu users. Some Xiaohongshu account management software can help users manage multiple accounts more easily, including automatic content publishing, scheduled publishing, data analysis and other functions. Through these tools, users can manage their accounts more efficiently and increase their account exposure and attention. In addition, Xiaohongshu account management software has

See all articles