首先,检查你的blog demo里的protectedmodelsComment.php,确保Comment模型有一个search的方法,如果没有,就用gii生成一个,我下载到的blog demo里倒是没有。
然后,写代码的时间到了,我们从 CommentController 开始,我们给它加一个 actionList:
代码如下 | 复制代码 |
public function actionList() { $model=new Comment('search'); $model->unsetAttributes(); if(isset($_GET['Comment'])) $model->attributes=$_GET['Comment']; $this->render('list',array( 'model'=>$model, )); } |
代码如下 | 复制代码 |
breadcrumbs=array( 'Comments', ); ?> Manage Commentswidget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns' => array( 'content', 'post.title', 'status', 'author' ), )); ?> |
代码如下 | 复制代码 |
'columns'=>array( 'content', 'post.title', 'status', 'author', ), |
代码如下 | 复制代码 |
private $_postTitle = null; public function getPostTitle() { if ($this->_postTitle === null && $this->post !== null) { $this->_postTitle = $this->post->title; } return $this->_postTitle; } public function setPostTitle($value) { $this->_postTitle = $value; } |
代码如下 | 复制代码 |
public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( array('content, author, email', 'required'), array('author, email, url', 'length', 'max'=>128), array('email','email'), array('url','url') array('content, postTitle, status, author', 'safe', 'on'=>'search'), ); } |
代码如下 | 复制代码 |
$criteria=new CDbCriteria; $criteria->with = "post"; // 确保查询 post 表 $criteria->compare('t.content',$this->content,true); $criteria->compare('t.status',$this->status); $criteria->compare('t.author',$this->author,true); $criteria->compare('post.title', $this->postTitle,true); |
代码如下 | 复制代码 |
$sort = new CSort(); $sort->attributes = array( 'defaultOrder'=>'t.create_time DESC', 'content'=>array( 'asc'=>'t.content', 'desc'=>'t.content desc', ), 'status'=>array( 'asc'=>'t.status', 'desc'=>'t.status desc', ), 'author'=>array( 'asc'=>'t.author', 'desc'=>'t.author desc', ), 'postTitle'=>array( 'asc'=>'post.title', 'desc'=>'post.title desc', ), ); |
代码如下 | 复制代码 |
return new CActiveDataProvider('Comment', array( 'criteria'=>$criteria, 'sort'=>$sort )); return new CActiveDataProvider('Comment', array( 'criteria'=>$criteria, 'sort'=>$sort )); |
代码如下 | 复制代码 |
'columns'=>array( 'content', 'postTitle', 'status', 'author', ), |
樱花校园模拟器4399中文版
樱花校园模拟器4399中文版,十分奇趣好玩的3d校园冒险模拟
我的暑假秘密回忆繁星新春版
我的暑假秘密回忆繁星新春版是一款少女模拟养成类休闲游戏。这款
樱花校园模拟器国际版
樱花校园模拟器国际版,一个超级自由超级好玩的自由恋爱模拟的游
饥荒海难九游版
饥荒海难九游版,带你去真实的海岛上感受一下什么才是真正的孤岛
盖瑞模组体验版最新版
盖瑞模组体验版是玩法非常丰富多元化的沙盒建造游戏,玩家可以在