2017-06-21 40 views
0

我正在面对yii2中使用的材料设计单选按钮的问题。 这是材料设计单选按钮,这是工作完美如何在yii2中编写材料设计单选按钮?

<div class="radio"> 
    <label> 
    <input type="radio" name="q_option" value="Recent advances in MS"> 
    Recent advances in MS 
    </label> 
</div> 

,但是当我在yii2框架写相同的单选按钮,单选按钮点变得消失,成为非可点击

<div class="radio"> 

     <?= $form->field($model, 'q_option')->radio(
      ['label' => 'Recent advances in MS', 'value' => 'Recent advances in MS'] 
     ) ?> 

</div> 

请指导我。提前致谢。

回答

0

也许你是指单选按钮?单收音机没有意义。

//controller 
$model = new Cities(); 
     return $this->render('index', [ 
      'model' => $model, 
     ]); 

//view <?php 
use yii\bootstrap\ActiveForm; 
?> 
<?php $form = ActiveForm::begin() ?> 
<div class="radio"> 
     <?= $form->field($model, 'city_name')->radio(
      ['label' => 'Recent advances in MS', 'value' => 'Recent advances in MS'] 
     ) ?> 
</div> 
<?php $form::end() ?> 

工作做好

您使用$模型和table_field_name。也许你尝试使用单选按钮列表?像这样:

//view 
$model = new Cities(); 
     return $this->render('index', [ 
      'model' => $model, 
      'array' => Cities::find()->all(), 
     ]); 

//controller 
<?php 
use yii\bootstrap\ActiveForm; 
use yii\helpers\ArrayHelper; 
?> 
<?php $form = ActiveForm::begin() ?> 
<?= $form->field($model, 'city_name') 
    ->radioList(ArrayHelper::map($array, 'id', 'city_name')) ?> 
<?php $form::end() ?>