2015-10-19 83 views
2

在單選按鈕中,值即將到來。但是,我想顯示該值的名稱。單選按鈕 - Yii2-Basic-App

user_types(表)

id   type    status   created_at 
1   An Individual  1     2015 
2   Firm    1     2015 

UserController.php(控制器)

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(視圖)

. 
. 
<?=       
    $form->field($model, 'user_type') 
    ->radioList($type) 
    ->label('Are You')  
?> 
. 
. 

這是這樣的。 enter image description here

我想這樣 enter image description here

所以任何想法如何把'type'列中顯示,而不是'id'列。

回答

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

    } 
+0

哈哈:D Wooaahhh .. !!偉大的Nuriddin。偉大的一個。非常感謝。我不知道如何謝謝你。 –

+0

不提及它。我很樂意幫助你;) –

+0

嘿@Nuriddin我在這裏問了一個關於Yii2的問題。如果你是免費的,你可以幫我嗎? http://stackoverflow.com/questions/33759514/model-save-not-working-in-yii2 –