php - Yii 过滤器未显示在 CGridView 中

标签 php mysql yii

我在过滤 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/

相关文章:

php - 将复选框选定的行保存到php中的数据库中

php - 时区 : Mysql save UTC and PHP read America/Sao_Paulo

php - Yii:优化 LEFT OUTER JOIN 到 INNER JOIN

php - 使用 PHP 处理 GET 参数中的 unicode 值

php - 当从表中更新列行时,然后在该列的所有行中提取

php - 使用范围 + 毕达哥拉斯定理选择结果

php - 用于嵌套/无限子类别的 Laravel 查询或函数

MySql - 当它匹配条件时如何设置新值?

mysql - 多列索引对单列也有用吗?

php - 如何修复 Yii2 View 中的 "Undefined variable"错误?