目前我的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
));
答案 0 :(得分:1)
您应该尝试使用radioButtonList并指定该列属于raw
类型:
'columns'=>array(
... //other columns
array(
'name'=> 'test',
'type'=>'raw',
'value' => 'CHtml::radioButtonList("test", $select,array("key" => "value"), array("template" => "{input}", "separator"=>" "))',
),
),
),
如果你不知道如何使用radioButtonList,你应该检查一下documentation