我创建了下拉过滤器,它显示了,但是没有正常工作。我在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,
));
}
答案 0 :(得分:1)
我理解了我的错误,我的控制器应该是这样的:
public function actionIndex()
{
$model=new Tasks;
if(isset($_REQUEST['Tasks']))
$model->attributes=$_GET['Tasks'];
$this->render('index',array(
'model'=>$model
));
}
我忘记了从控制器到模型的传递参数。大家好!
答案 1 :(得分:0)
检查rules
方法。对于client_id
safe
应该在search
public function rules()
{
return array(
array('client_id', 'safe', 'on'=>'search'),
);
}
答案 2 :(得分:0)
检查this wiki,它会详细解释您的需求。