【发布时间】:2014-07-30 11:49:49
【问题描述】:
我有 3 张桌子。 汽车类型:
id | main_image | title
car_type_classifiers:
id | car_type_id | classifier_id
分类器:
id | class
我想显示一个 CGridView 所以有列:标题 |班级。但是一个 car_type 可以有很多类。我尝试在网上搜索,但无法理解模型搜索功能中的那些$criteria->compare() 功能。
我希望这些显示为小列表。我怎样才能做到这一点? 我的看法:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'car-type-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns' => array(
'title'
),
));
我的控制器:
public function actionIndex()
{
$model=new EeCarTypes('search');
$model->unsetAttributes();
$this->render('index',array('model'=>$model));
}
还有我的模特:
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('car_type',$this->car_type,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
【问题讨论】: