4
我有一个CGridView部件的课程模式搜索与CGridView belongs_to的模型柱,Yii的
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'lesson-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
...和教训关系到用户模式:
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
...和该CGridView有从上面
'columns'=>array(
...
array(
'name' => 'user',
'header'=>'Teacher',
'value' => '$data->user->lastname',
),
这样描述的belongs_to的模型用户的姓氏列,我不能symply与CG搜索ridView在这个列中,但我需要它。
如何使用CGridView搜索'$ data-> user-> secondname'?
我认为我应该在课程模型中扩展搜索方法,但是怎么做?
现在看起来是这样的:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('student',$this->student,true);
$criteria->compare('comment',$this->comment,true);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
非常感谢!除了你没有人没有给出答案.... – Kir 2011-02-02 04:32:13