在Controller中加上: ?
1
2
3
4
5
6
7
8
9
10
11
| publicfunctionactionIndex()
{
$model=newUser('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['User']))
$model->attributes=$_GET['User'];
$this->render('admin',array(
'model'=>$model,
));
}
|
在Model中加上: ?
1
2
3
4
5
6
7
8
9
10
11
| publicfunctionsearch()
{
$criteria=newCDbCriteria;
$criteria->compare('username',$this->username,true);
$criteria->compare('email',$this->email,true);
returnnewCActiveDataProvider($this,array(
'criteria'=>$criteria,
));
}
|
在View中显示: ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| $this->widget('zii.widgets.grid.CGridView',array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'username',
'email',
array(
'header'=>'ABC',
'value'=>'CHtml::Link("Link", Yii::app()->createUrl("index"))',
'type'=>'raw',
),//添加链接
array(
'class'=>'CButtonColumn',
),
),
));
?>
|
|
|