Php 如何在Yii中使用CGridView过滤时排除CActiveRecord属性?
在Yii 1.1应用程序中,我使用Php 如何在Yii中使用CGridView过滤时排除CActiveRecord属性?,php,yii,cgridview,yii-cactiverecord,cactiverecord,Php,Yii,Cgridview,Yii Cactiverecord,Cactiverecord,在Yii 1.1应用程序中,我使用CGridView将数据显示在表格中 $dataProvider = $model->search(); $this->widget('zii.widgets.grid.CGridView', array( 'id' => 'my-grid', 'dataProvider' => $dataProvider, 'filter' => $model, 'columns' => array(
CGridView
将数据显示在表格中
$dataProvider = $model->search();
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'my-grid',
'dataProvider' => $dataProvider,
'filter' => $model,
'columns' => array(
'id',
'user.firstname',
'user.lastname',
'user.email',
'type',
'foo', // <-- on-the-fly added attribute
'bar', // <-- on-the-fly added attribute
...
),
));
$dataProvider=$model->search();
$this->widget('zii.widgets.grid.CGridView',数组(
'id'=>'my grid',
“dataProvider”=>$dataProvider,
“过滤器”=>$model,
'列'=>数组(
“id”,
“user.firstname”,
“user.lastname”,
“user.email”,
“类型”,
‘foo’,//这里有一个解决方案,看起来像是一个解决办法——只需明确定义未筛选的属性,并将每个属性的filter
参数设置为false
:
...
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'my-grid',
'dataProvider' => $dataProvider,
'filter' => $model,
'columns' => array(
'id',
...
'type',
array(
'name' => 'foo',
'filter' => false,
),
array(
'name' => 'bar',
'filter' => false,
),
...
),
));
它可以工作,但我认为,应该有一个更优雅的解决方案…这里有一个解决方案,看起来像是一个解决办法——只需明确定义未筛选的属性,并将每个属性的过滤器
参数设置为false
:
...
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'my-grid',
'dataProvider' => $dataProvider,
'filter' => $model,
'columns' => array(
'id',
...
'type',
array(
'name' => 'foo',
'filter' => false,
),
array(
'name' => 'bar',
'filter' => false,
),
...
),
));
这是可行的,但我认为,应该有一个更优雅的解决方案