Reputation: 125
Currently I have CGridView with columns from few joined tables, but also I need to add additional columns from other table, and I can not join it with first tables, because there is no relations between them.
Second table 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
I need to get 4 additional columns in CGridView with radio buttons generated (one buttom per column) from the table above (with values 0,1,2,3).
model file:
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);
}
}
controller file:
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));
}
}
view file:
$this->widget('CGridViewPlus', array(
'dataProvider' => $dataProvider,
'addingHeaders' => array(
$columns_top, // first header row
),
'columns' => $columns_main //second header row
));
Upvotes: 0
Views: 245
Reputation: 8950
You should try to use a radioButtonList and specify that the column is of a raw
type:
'columns'=>array(
... //other columns
array(
'name'=> 'test',
'type'=>'raw',
'value' => 'CHtml::radioButtonList("test", $select,array("key" => "value"), array("template" => "{input}", "separator"=>" "))',
),
),
),
If you don't know how to use a radioButtonList you should check the documentation about it
Upvotes: 1