dqx76962 2014-10-19 00:25
浏览 89
已采纳

Yii Framework 1.1 .. CGridview过滤器不能与我自己的搜索功能一起使用到模型中

i had clone search function into model, use it in controller pass to my view to use CGridview, the result data is correct but filters stop working, i can't see any difference so there must be something more else to add. This are the sections of my code: Model:

public function searchCargo()
   {
     $criteria=new CDbCriteria;
     $criteria->compare('cargoResp',1,true);
     return new CActiveDataProvider($this, array(
                              'criteria'=>$criteria,
                          ));
   }

Controller

$modRespSearchC=new Responsables('searchCargo');

$modRespSearchC->unsetAttributes();
if(isset($_GET['Responsables']))
   $modRespSearchC->attributes=$_GET['Responsables'];

CGridView:

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'responsables-grid1',
'dataProvider'=>$modRespSearchC->searchCargo(),
'filter'=>$modRespSearchC,

'columns'=>array(
           'apell1Resp',
           'apell2Resp',
           'cargoResp',.....

what i had miss?? how can use filters with my own functions??

  • 写回答

1条回答 默认 最新

  • duanmanmian7589 2014-10-19 11:09
    关注

    The other search conditions are missing. However since they exist in the search function all you need to do is call that function as below:

    public function searchCargo() {
        $dataProvider = $this->search();
        $dataProvider->criteria->compare('cargoResp',1,true); 
        return $dataProvider;
    }
    

    Also unless you have added rules for searchCargo in your model's rules method, your scenario should be search i.e

    $modRespSearchC=new Responsables('search')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像