以我的形式,我有8-9份档案。其中所有的都是硬编码的,除了一个,它应该来自数据库。
UsersControllers.php (控制器)
public function actionRegister()
{
.
.
model = new Users();
$modelUserType=UserType::find()->select(['id', 'type'])->where(['status' => 1])->all();
return $this->render('register', [
'model' => $model,
'modelUserType'=>$modelUserType,
'module' => $this->module,
]);
}如果我做print_r($modelUserType);的话,值就会出现
但是,我不知道在视图中为单选按钮显示所有的"UserType“表值。
<?=
$form->field($modelUserType, 'user_type')
->radioList(array('1' => 'An Individual', '2' => 'Firm')) // Here.
->label('Are You')
?>register.php (视图)
.
.
<?= $form->field($model, 'password')->passwordInput()->label('Password') ?>
<?= $form->field($model, 'confirm_password')->passwordInput()->label('Confirm Password') ?>
<?=
$form->field($model, 'user_type')
->radioList(array('1' => 'An Individual', '2' => 'Firm'))
->label('Are You')
?>
<?= $form->field($model, 'company_name')->textInput() ?>
.
.我没有得到任何教程,或我无法找到正确的教程为它。不需要什么帮助。请帮帮我。谢谢。
发布于 2015-10-19 16:16:38
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/33218947
复制相似问题