问题
In radio button, value is coming. But, I want to display the name of that value.
my user_types (table)
id type status created_at
1 An Individual 1 2015
2 Firm 1 2015
UserController.php (controller)
public function actionRegister()
{
$model = new Users();
.
.
$modelUserType=UserType::find()->select(['id', 'type'])->where(['status' => 1])
->indexBy("id")->column();
return $this->render('register', [
'model' => $model,
'modelUserType'=>$modelUserType,
'module' => $this->module,
]);
}
register.php (view)
.
.
<?=
$form->field($model, 'user_type')
->radioList($type)
->label('Are You')
?>
.
.
It's coming like this.
I want like this
So any idea how to bring 'type'
column to display instead of 'id'
column.
回答1:
Mr Partykar and now i understand you.This is my answer.This is work to me also for render list of radio buttons. Please, reply this is fix your problem
public function actionRegister()
{
$model = new Users();
.
.
$modelUserType=UserType::find()->select(['id', 'type'])->where(['status' => 1])->asArray()->all();
$type=[];
foreach($modelUserType as $k=>$v){
if(is_array($v))$type[$v["id"]]=$v["type"];
}
return $this->render('register', [
'model' => $model,
'type'=>$type,
'module' => $this->module,
]);
}
来源:https://stackoverflow.com/questions/33221404/radio-button-yii2-basic-app