我创建了下拉过滤器,它可以显示,但不能正常工作。当我理解 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,
));
}