[英]Yii 2 - radioList Template
I want to add template to radioList in yii2, which I tried, but I am unable to get the proper o/p. 我想将模板添加到yii2中的radioList中,但是我无法获得正确的o / p。
The HTML is HTML是
<div class="input-wrap">
<label class="gender-head">Gender</label>
<label class="signup-radio">
<input type="radio" name="signup-gender" id="signupMale" checked tabindex="3" />
<i></i>
<span>Male</span>
</label>
<label class="signup-radio">
<input type="radio" name="signup-gender" id="signupFemale" tabindex="3" />
<i></i>
<span>Female</span>
</label>
</div>
The o/p should look like this o / p应该看起来像这样
The Yii2 code which I tried is... 我尝试过的Yii2代码是...
<div class="input-wrap">
<div class="clearfix">
<?= $form->field($model, 'gender', ['radioTemplate' => '<label class="gender-head">{label}</label><label class="signup-radio">{input}</label>'])->inline()->radioList([1 => 'Male', 0 => 'Female'], ['separator' => '', 'tabindex' => 3]); ?>
</div>
<div class="help-block"></div>
</div>
I have searched a lot on the template but did not get any proper response. 我在模板上进行了大量搜索,但未得到任何适当的答复。
I finally got the way through which we can modify the input tag generation logic in Yii2 我终于找到了在Yii2中修改输入标签生成逻辑的方法
To get the above result of the radio buttons, I have developed the following code 为了获得单选按钮的上述结果,我开发了以下代码
<div class="input-wrap">
<div class="clearfix" id="UserLogin-gender">
<label class="radio-head">Gender</label>
<?=
$form->field($model, 'gender')
->radioList(
[1 => 'Male', 0 => 'Female'],
[
'item' => function($index, $label, $name, $checked, $value) {
$return = '<label class="modal-radio">';
$return .= '<input type="radio" name="' . $name . '" value="' . $value . '" tabindex="3">';
$return .= '<i></i>';
$return .= '<span>' . ucwords($label) . '</span>';
$return .= '</label>';
return $return;
}
]
)
->label(false);
?>
</div>
<div class="help-block"></div>
</div>
The "item" option in the radioList is a callback function to the input generation logic written in Yii2. radioList中的“ item”选项是使用Yii2编写的输入生成逻辑的回调函数。 We can easily modify the layout of each element generated using this callback function and it's parameters. 我们可以轻松地修改使用此回调函数及其参数生成的每个元素的布局。
$form->field($model, 'gender')
->radioList(array(1 => 'Male', 0 =>'Female'), array('class' => 'i-checks'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.