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 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面