2

我创建了下拉过滤器,它可以显示,但不能正常工作。当我理解 search() 方法的麻烦时

看法:

   $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,
    ));
}
4

3 回答 3

1

我理解我的错误,我的控制器应该是这样的:

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

我忘记了从控制器到模型的传递参数。谢谢!

于 2012-10-09T08:43:49.350 回答
0

检查这个 wiki,它以详细的方式准确地解释了您需要什么。

于 2012-10-07T22:55:40.570 回答
0

检查rules方法。client_id应该safesearch

public function rules()
{
    return array(
        array('client_id', 'safe', 'on'=>'search'),
    );
}
于 2012-10-07T21:01:20.913 回答