我在过滤 CGridView 时遇到问题。我在 studProg/view 中做这一切: 在这里,我基于另一个名为 kurs 的表/模型创建了 CGridView,我得到了数据,一切正常。现在我希望能够从另一个表中获取键值对并将它们列在我的 CGrid 的过滤器选项中。但是,下拉列表不会显示。为什么?
以下是我的代码的重要部分:
studProg/查看 CGridView 主体:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'kursData',
'dataProvider'=>$kursDataProvider,
'columns'=>array(
array(
'header' => 'Studijska godina',
'type' => 'raw',
'filter' => $model->getStudijskeGodine(),
'value' => '$data->stud_god_god'
),etc..
来自 StudProg 模型:
public function getStudijskeGodine()
{
$query = 'select god from stud_god';
$rezultat = Yii::app()->db->createCommand($query)->queryAll();
$spisak = CHtml::listData($rezultat, 'god' , 'god');
return $spisak;
}
最佳答案
首先在 GridView 中配置过滤器
。请记住,自定义过滤器始终与 name
属性一起使用。
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'kursData',
'dataProvider'=>$kursDataProvider,
'filter'=>$model, //Need this property to get the filter.
'columns'=>array(
array(
'header' => 'Studijska godina',
'name'=>'stud_god_god', //Need this filter
'type' => 'raw',
'filter' => $model->getStudijskeGodine(),
'value' => '$data->stud_god_god'
)
关于php - Yii 过滤器未显示在 CGridView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35132108/