CGridView中的过滤器不过滤

时间:2015-05-01 12:17:03

标签: yii filter widget cgridview dataprovider

你能检查为什么过滤在CGridView中不起作用吗?当我在过滤器字段中输入'Adam'时,没有任何反应。我找不到我的错误,一切看起来都不错但不起作用。我帮助了那篇文章:How do I query using fields inside the new PostgreSQL JSON datatype?

CONTROLLER

 <?php
    class UzytkownikController extends CController
    {
        public function actionIndex()
        {
            $Dane = new Uzytkownik('search');
            $Dane -> unsetAttributes();  // clear any default values
            if(isset($_GET['Uzytkownik']))
            {
                $Dane->attributes=$_GET['Uzytkownik'];
            }
            $this -> render ('index', array(
                'Dane' => $Dane,
            ));
        }
    }
    ?>

MODEL

<?php
class Uzytkownik extends CActiveRecord
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function search()
    {
        $criteria = new CDbCriteria;
        $criteria -> compare('imie', $this -> imie, true);

        return new CActiveDataProvider($this, array(
                'criteria' => $criteria,
                )
        );
    }
}

?>

enter image description here

WIEV

<?php 
    $this -> widget('zii.widgets.grid.CGridView', array(
        'dataProvider' => $Dane -> search(),
        'filter' => $Dane,
        'columns' => array(
                array(
                    'name' => 'imie',
                    'type'=>'raw',
                ),
                array(
                    'name' => 'nazwisko',
                    'type'=>'raw',
                    'filter' => false,
                ),
                array(
                    'name' => 'data',
                    'filter' => false,
                ),
            ), 
        )
    );
?>

enter image description here

1 个答案:

答案 0 :(得分:0)

供将来参考:

为了确保$model->attributes“保存”model所需的属性,需要添加以下内容:

public function rules() {
    return array(
      array('imie', 'safe', 'on'=>'search')
    );
}

应该使用$_GET代替$_POST因为CGridView窗口小部件在发布到服务器时使用GET

class UzytkownikController extends CController
{
    public function actionIndex()
    {
        $Dane = new Uzytkownik('search');
        $Dane -> unsetAttributes();  // clear any default values
        if(isset($_GET['Uzytkownik']))
        {
            $Dane->attributes=$_GET['Uzytkownik'];
        }
        $this -> render ('index', array(
            'Dane' => $Dane,
        ));
    }
}