我在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 :(得分: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() ?>
运作良好
您使用$ model和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() ?>