单选按钮 - Yii2-Basic-App [英] Radio Button - Yii2-Basic-App
本文介绍了单选按钮 - Yii2-Basic-App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在单选按钮中,值来了.但是,我想显示该值的名称.
我的user_types(表格)
id type status created_at1 个人 1 20152 事务所 1 2015
UserController.php(控制器)
公共函数 actionRegister(){$model = 新用户();..$modelUserType=UserType::find()->select(['id', 'type'])->where(['status' => 1])->indexBy("id")->column();返回 $this->render('注册', ['模型' =>$模型,'modelUserType'=>$modelUserType,'模块' =>$this->模块,]);}
register.php(查看)
<预><代码>..<?=$form->field($model, 'user_type')->radioList($type)->label('你是你吗')?>..事情是这样的.
我想要这样
所以知道如何显示 'type'
列而不是 'id'
列.
解决方案
Partykar 先生,现在我理解你了.这是我的答案.这对我来说也适用于呈现单选按钮列表.请回复这是解决您的问题
公共函数 actionRegister(){$model = 新用户();..$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"];}返回 $this->render('注册', ['模型' =>$模型,'类型'=>$类型,'模块' =>$this->模块,]);}
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.
解决方案
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,
]);
}
这篇关于单选按钮 - Yii2-Basic-App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文