目前我有 CGridView 与来自几个连接表的列,但我还需要从其他表中添加额外的列,我不能将它与第一个表连接,因为它们之间没有关系。
第二张表assessment_rate
:
id title_id rate users_id date_entry
0 2137 0 1 2013-08-28 08:43:54.000000
1 2139 1 1 2013-08-28 08:47:13.000000
2 2140 2 1 2013-08-28 08:57:44.000000
3 2141 3 1 2013-08-28 08:59:10.000000
我需要在 CGridView 中获取 4 个附加列,并从上表中生成单选按钮(每列一个按钮)(值为 0、1、2、3)。
模型文件:
class form extends CActiveRecord {
public function init() {
Yii::import('application.modules.admin.models.user');
Yii::import('application.modules.admin.models.language');
}
public function tableName() {
return 'ass_competence';
}
public function relations() {
return array(
'lan' => array(self::BELONGS_TO, 'language', 'title_id'),
'lan_desc' => array(self::BELONGS_TO, 'language', 'description_title_id'),
'use' => array(self::BELONGS_TO, 'user', 'users_id'),
'rela' => array(self::BELONGS_TO, 'relation', array('id' => 'record_id')),
);
}
public function attributeLabels() {
return array(
'lan.name_lt' => Yii::app()->reg->lang['title'],
'use.username' => Yii::app()->reg->lang['user'],
'lan_desc.name_lt' => Yii::app()->reg->lang['description'],
'date_entry' => Yii::app()->reg->lang['date_entry'],
'assessment' => Yii::app()->reg->lang['assessment'],
);
}
public function search() {
$criteria = new CDbCriteria;
$criteria->with = array('use', 'lan', 'rela', 'lan_desc');
$criteria->addCondition('rela.record_id IS NULL');
$criteria->group = 't.id';
$criteria->order = 't.id ASC';
$criteria2 = new CDbCriteria;
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
public static function model($className = __CLASS__) {
return parent::model($className);
}
}
控制器文件:
class FormController extends ControllerDefault {
public $model_name = 'Form';
public function beforeActionConfig() {
$this->reg['title'] = Yii::app()->reg->lang['players'];
}
public function actionIndex() {
$model = new form('search');
$columns_top = array('' => 2,
Yii::app()->reg->lang['assessment'] => 4,
);
$columns_main = array('lan.name_lt',
'lan_desc.name_lt',
'CountryName' => array(
'header' => 'Country',
'name' => 'Name',
'value' => '1',
),
);
$dataProvider = $model->search();
$this->render('index', array('model' => $model, 'dataProvider' => $dataProvider, 'columns_main' => $columns_main, 'columns_top' => $columns_top));
}
}
查看文件:
$this->widget('CGridViewPlus', array(
'dataProvider' => $dataProvider,
'addingHeaders' => array(
$columns_top, // first header row
),
'columns' => $columns_main //second header row
));