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.

Nana Partykar
  • 10,175
  • 8
  • 43
  • 73

1 Answers1

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

    }
  • Ha Ha :D Wooaahhh..!! Great Nuriddin. Great One. Thank You So Much. I don't know How to Thank You. – Nana Partykar Oct 19 '15 at 18:48
  • don't mention it. i'm just happy to help you ;) – Nuriddin Rashidov Oct 19 '15 at 18:50
  • Hey @Nuriddin I asked one question here regarding Yii2. If you are free, can you please help me. http://stackoverflow.com/questions/33759514/model-save-not-working-in-yii2 – Nana Partykar Nov 17 '15 at 14:52
  • Hi @nuriddin: If i want to select one radio button as selected, then how to do ? This question only. – Nana Partykar Dec 04 '15 at 14:46
  • Hi there different ways and it's related exact situation. e.g :if you want set selected deafult radio button - you can do this with setting value of radio button as default value ['value' => $defaultvalue]. or init user_type prop in your model : $model->user_type=$defaultvalue; – Nuriddin Rashidov Dec 04 '15 at 17:03
  • Hi @nuriddin: Do you have any idea about this http://stackoverflow.com/questions/36888464/two-different-layouts-for-guest-user-logged-in-user-yii2 – Nana Partykar Apr 27 '16 at 11:32