Yii Cgridview过滤器无法正常工作?

时间:2016-10-04 11:36:24

标签: yii

我正在尝试在Cgridview中实现一个下拉过滤器,该列来自另一个表。

 //model search code 

  //person table 
   public function search(){
    $criteria=new CDbCriteria;
      $criteria->alias='per';      
    $criteria->compare('LastName',$this->LastName,true);    
    $criteria->compare('FirstName',$this->FirstName,true);         
     $criteria->join='right JOIN person_surveys ps ON ps.id = per.P_Id'; 

   }
  //relation to person survey

   public function relations()
{

    return array(

        'user' => array(self::BELONGS_TO, 'PersonSurvey', 'P_Id'),

    ); 

}

   //person survey table model search 

    public function search()
{


    $criteria=new CDbCriteria;    
    $criteria->compare('person_id',$this->person_id,true);    
    $criteria->compare('survey_ids',$this->survey_ids,true);          
     $criteria->join='left JOIN persons ps ON ps.id = per.P_Id';  

   }  

   //controller 
   public function actiongriddisplay(){

        $model2=new Persons('search'); 
         if(isset($_GET['ajax'])){ 

        $model2->attributes =$_GET['Persons'];
        $this->render('griddisplay',array('model2'=>$model2));    
        }

        else{

            $this->render('griddisplay',array('model2'=>$model2)); 
     }


    }

    //in view file

    $this->widget('zii.widgets.grid.CGridView', array(      
        'dataProvider' => $model2->Search(),
        'filter' => $model2,
        'ajaxType'=>'GET',
       // 'ajaxUpdate'=>'items',
        //'ajaxUrl' =>$this->createUrl('userManagement'),   
        'columns' => array(             
              array(
         'name' => 'FirstName',
         'header'=>'Full Name', 

            ),
           array(
     'name' => 'user.survey_ids',
     'header'=>'Survey ids',    

    'filter'=>CHtml::activeDropDownList($model2  ,'survey_ids', array('224'=>'224','223'=>'223','225'=>'225')),  

           'value'=>'isset($data->user->survey_ids)?$data->user->survey_ids:null'

        ),   

我在模特中进行了搜索。为什么下拉过滤器不起作用? 为什么这不起作用请帮忙?

1 个答案:

答案 0 :(得分:0)