0

In my form, I'm having 8-9 fileds. In which all are hard-coded, Except one, which should come from database.

UsersControllers.php (controller)

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,
      ]);
}

Values are coming if i do print_r($modelUserType);

But, i don't know to show all those "UserType" table values in views for radio button.

<?=
    $form->field($modelUserType, 'user_type')
    ->radioList(array('1' => 'An Individual', '2' => 'Firm')) // Here.
    ->label('Are You')
?>

register.php (view)

.
.

<?= $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() ?>
.
.

I'm not getting any tutorials or I am not able to find the correct tutorials for it. Little help needed. Please help me. Thanks.

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77

1 Answers1

2
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,
    ]);
}