2012-10-07 60 views
2

我創建了下拉篩選器,它是顯示器,但不能正常工作。正如我在search()方法anderstand麻煩Yii CGridView和下拉篩選器

觀點:

$this->widget('zii.widgets.grid.CGridView', array(
     'dataProvider'=>$model->search(), 
     'filter' => $model, 
     'columns'=>array(
      array(
       'name' => 'client_id', 
       'filter' => CHtml::listData(Client::model()->findAll(), 'client_id', 'name'), 
       'value'=>'$data->client->name' 
      ), 
      'task' 
     ) 
    )); 

我有表,他們關係如圖下來 型號:

public function relations() 
{ 
    // NOTE: you may need to adjust the relation name and the related 
    // class name for the relations automatically generated below. 
    return array(
     'client' => array(self::BELONGS_TO, 'Client', 'client_id'), 
    ); 
} 

public function search() 
{ 
    // Warning: Please modify the following code to remove attributes that 
    // should not be searched. 

    $criteria=new CDbCriteria; 
    $criteria->with = array('client'); 
    $criteria->compare('task_id',$this->task_id); 
    $criteria->compare('client_id',$this->client_id); 
    $criteria->compare('name',$this->client->name); 
    $criteria->compare('task',$this->task,true); 
    $criteria->compare('start_date',$this->start_date,true); 
    $criteria->compare('end_date',$this->end_date,true); 
    $criteria->compare('complete',$this->complete); 

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

它不工作?什麼是輸出? – Stu

+0

我認爲這個wiki可能有一些幫助: [CGridView:Render customized/complex datacolumns](http://www.yiiframework.com/wiki/278/cgridview-render-customized-complex-datacolumns/) – Stu

+0

它的輸出與之前的filterin一樣,我認爲$ this-> client_id在CDbCriteria –

回答

0

檢查rules方法。 client_id應在safesearch

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

檢查this wiki,它正好說明你在一個詳細的方式所需要的。

+0

中沒有正常工作,我試過了,但也沒有結果。排序工作正常,但按下拉列表中的值進行搜索不起作用 –

+0

as mashingan said,檢查你是否有一個安全的client_id規則,以便可以批量分配 – Asgaroth

+0

array('task_id,client_search,task,start_date,end_date,完整,client_id','安全','on'=>'搜索') –

1

我anderstand我的錯,我的控制器看起來應該是這樣:

public function actionIndex() 
{ 
    $model=new Tasks; 
    if(isset($_REQUEST['Tasks'])) 
     $model->attributes=$_GET['Tasks']; 
    $this->render('index',array(
     'model'=>$model 
    )); 
} 

我forgout從控制器到模型通過parametrs。 Thx所有!