温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在ThinkPHP中利用无限级分类实现一个留言与回复功能

发布时间:2020-12-21 15:56:03 来源:亿速云 阅读:175 作者:Leah 栏目:开发技术

这篇文章将为大家详细讲解有关怎么在ThinkPHP中利用无限级分类实现一个留言与回复功能,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

数据表:

复制代码 代码如下:

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

代码:

复制代码 代码如下:

<?php    
// +----------------------------------------------------------------------    
// | WBlog    
// +----------------------------------------------------------------------    
// | Copyright (c) 2008  http://www.w3note.com 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');    
      }     
}    
?>    
<?php    
// +----------------------------------------------------------------------    
// | WBlog    
// +----------------------------------------------------------------------    
// | Copyright (c) 2008   http://www.w3note.com 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 < $list[$k]['count'] * 2; $i++) {    
                    $str .= '&nbsp;';    
                }    
                $str .= ' ';    
            }    
            $list[$k]['space'] = $str;    
        }    
        $P->setConfig('header', '篇');    
        $P->setConfig('prev', "&laquo;");    
        $P->setConfig('next', '&raquo;');    
        $P->setConfig('first', '|&laquo;');    
        $P->setConfig('last', '&raquo;|');    
        $page = $P->show();    
        $arr=array('page'=>$page,'list'=>$list);    
        return $arr;    
    }    
}    
?>

关于怎么在ThinkPHP中利用无限级分类实现一个留言与回复功能就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI