THINKPHP框架留言版

浏览:11612 发布日期:2013/06/09 分类:技术分享 关键字: 留言板
终于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操作中,都规定要用表名。
最佳答案
评论( 相关
后面还有条评论,点击查看>>