当前位置: 移动技术网 > IT编程>开发语言>PHP > 基于thinkPHP框架实现留言板的方法

基于thinkPHP框架实现留言板的方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

枪声2012.3.19解密,破解wifi,老父举牌寻目击者

本文实例讲述了基于thinkphp框架实现留言板的方法。分享给大家供大家参考,具体如下:

奋斗了一天,终于thinkphp小邓留言版的概念版出来了

其实真的thinkphp开发速度很快,作为一个互联网上“搬砖”的,从事这种 纯码农的事也是无可厚非的。

代码就实现了如下功能

1.留言功能。

2.验证功能。

3.分页显示功能。

就是写了几行代码(ps:页面设计代码不算,就算控制器和模型的代码)

下面我公布一下控制的器的代码,关于thinkphp的代码规则我就不阐述了,看thinkphp手册就可以了。

class indexaction extends action
{
  public function index() {
    $form = m("word");
    // 按照id排序显示前6条记录
    import("@.org.page");    //导入分页类
      $count = $form->count();  //计算总数
      $p = new page ( $count, 1 );
      $list=$form->limit($p->firstrow.','.$p->listrows)->order('id desc')->findall();
      $page = $p->show ();
      $this->assign ( "page", $page );
      $this->assign ( "list", $list );
    $this->display(); //模板调用,这个是关键。
  }
  //数据插入
  public function insert() {
    $word = d("word");
     if($vo = $word->create())
       {
         if(false !== $word->add())
        {
           $this->success("数据添加成功");
         }
         else
         {
          $this->error('数据写入错误!');
         }
       }
    else
      {
       $this->error($word->geterror());
      }
  }
  //验证重复
  public function checktitle()
  {
    if (!empty($_post['username'])) {
      $form = m("word");
      //getbytitle是model的获取数据根据某字段获取记录的魔术方法
      //比如getbyid etc getbyxxx xxx大写
      if ($form->getbyusername($_post['username'])) {
        $this->error('<font color=red>标题已经存在</font>');
      } else {
        $this->success('标题可以使用!');
      }
    } else {
      $this->error('标题必须');
    }
  }
}

下面是验证模型的代码

class wordmodel extends model{
  protected $_validate = array(
   array('username', 'require', '称呼必须!', 1),//1为必须验证
   array('email', 'email', '邮箱格式错误!', 2),//2为不为空时验证
   array('qq','number','qq号错误',2),
   array('content', 'require', '内容必须',1),
   array('username','','称呼已经存在',0,'unique',1)
  );
  protected $_auto = array(
   array('datetime', 'get_date',1, 'callback'),
   array('ip','getip',1,'callback')
  );
  protected function get_date()
  {
   return date("y-m-d h:i:s");
  }
  protected function getip()
  {
   return $_server['remote_addr'];
  }
}

thinkphp有一个要注意的,在curd操作中,都规定要用表名。

更多关于thinkphp相关内容感兴趣的读者可查看本站专题:《thinkphp入门教程》、《thinkphp模板操作技巧总结》、《thinkphp常用方法总结》、《smarty模板入门基础教程》及《php模板技术总结》。

希望本文所述对大家基于thinkphp框架的php程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网