doubi8512 2012-03-31 19:47 采纳率: 0%
浏览 23
已采纳

Yii CGridview没有过滤

I'm trying to work with a YII CGridview to display some data.

This is home my model search function looks like:

/**
 * Retrieves a list of models based on the current search/filter conditions.
 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
 */
public function search()
{
    $criteria=new CDbCriteria;
    $criteria->compare('ip',$this->ip,true);
    $criteria->compare('first_use',$this->first_use,true);
    $criteria->compare('last_use',$this->last_use);
    $criteria->compare('memberid',$this->memberid);
    $criteria->compare('countryid',$this->countryid);

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

And this is how my view looks like

$this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'iplog-grid',
        'dataProvider'=>$oIPLog->search(),
        'filter'=>$oIPLog,
        'summaryText' => 'showing you {start} - {end} of {count} logged Ips',
        'columns'=>array(
            array(
                'name'=>'ip',
                'type'=>'raw',
            ),
            array(
                'name'=>'first_use',
                'type'=>'datetime',
            ),
            array(
                'name'=>'last_use',
                'type'=>'datetime',
            ),
        ),
    ));

Displaying the CGridview works, but I can't seem to get the filter on top of it to work. It sends the call and I don't get any error as reponse, it just returns the whole unfiltered data again..

Any clues?

  • 写回答

2条回答 默认 最新

  • dousi4257 2012-03-31 20:00
    关注

    And how exactly does your controller look like?

    For the CGridview filter to work you need to check in your controller if there are any filters set and then return the filtered object.

    To clarify, something like this should be placed into your controller action

    $oObject = new Object('search');
    if (isset($_GET['Object'])) {
        $oObject->attributes = $_GET['Object'];
    }
    

    Hope this helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件