单选按钮 - Yii2-Basic-App
Radio Button - Yii2-Basic-App
在单选按钮中,值来了。但是,我想显示该值的名称。
我的user_types (table)
id type status created_at
1 An Individual 1 2015
2 Firm 1 2015
UserController.php(控制器)
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(查看)
.
.
<?=
$form->field($model, 'user_type')
->radioList($type)
->label('Are You')
?>
.
.
就这样来了。
我想要这样
所以知道如何显示 'type'
列而不是 'id'
列。
Partykar 先生,现在我明白 you.This 是我的 answer.This 对我来说也适用于呈现单选按钮列表。请回复,这是解决您的问题
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,
]);
}
在单选按钮中,值来了。但是,我想显示该值的名称。
我的user_types (table)
id type status created_at
1 An Individual 1 2015
2 Firm 1 2015
UserController.php(控制器)
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(查看)
.
.
<?=
$form->field($model, 'user_type')
->radioList($type)
->label('Are You')
?>
.
.
就这样来了。
我想要这样
所以知道如何显示 'type'
列而不是 'id'
列。
Partykar 先生,现在我明白 you.This 是我的 answer.This 对我来说也适用于呈现单选按钮列表。请回复,这是解决您的问题
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,
]);
}