Radio Button - Yii2-Basic-App

让人想犯罪 __ 提交于 2019-12-10 23:28:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!