嗨,我是使用Yii污物,並試圖從另一個表中添加一列管理視圖從另一個表添加列CGridView
這是我的管理視圖CGridView部件代碼。
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'package-days-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'package_days_id',
'package_days_description',
array(
'header' => 'Package Title',
'name' => 'package_days_package_id',
'value' => function ($data){
echo $data->packagePackagedays->package_title;
}
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
這是'PackageDays'模型中的關係函數。
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(
'packagePackagedays' => array(self::BELONGS_TO, 'Packages', 'package_days_package_id'),
);
}
這是'PackageDays'模型中的搜索功能。
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->with = "packagePackagedays";
$criteria->compare('package_days_id',$this->package_days_id);
$criteria->compare('packagePackagedays.package_title',$this->package_days_package_id);
$criteria->compare('package_days_description',$this->package_days_description,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
我成功添加列,但我不能搜索新 添加的列的值。
這將是巨大的,如果有人能尋找到它
維基http://www.yiiframework.com/wiki/ 590 /排序和過濾器-A-定製或複合-cgridview柱 - 其-MAY-偶數包含數據從 - 不同桌/ – SiZE