2

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. enter image description here

I want like this enter image description here

So any idea how to bring 'type' column to display instead of 'id' column.

4

1 回答 1

1

Partykar 先生,现在我明白了。这是我的回答。这对我来说也适用于单选按钮的渲染列表。请回复这是解决您的问题

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

    }
于 2015-10-19T18:36:19.973 回答