php 如何创建 yii2 内联复选框列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27657356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:27:55  来源:igfitidea点击:

How to create yii2 inline checkbox list

phphtmlcheckboxtwitter-bootstrap-3yii2

提问by black-room-boy

I have described my problem on yii2 forum, but no one helped me, most likely because no one knows the answer.

我已经在yii2 论坛上描述了我的问题,但没有人帮助我,很可能是因为没有人知道答案。

Here is the short description here.

这是这里的简短描述。

I would like to make this:

我想做这个:

<label class="checkbox-inline"><input type="checkbox" value="ASD">Option 1</label>
<label class="checkbox-inline"><input type="checkbox" value="DSA">Option 2</label>
<label class="checkbox-inline"><input type="checkbox" value="REW">Option 3</label>

but with yii2 checkboxList Html helper.

但是使用 yii2 checkboxList Html helper。

This is my simplified array of checkbox values

这是我简化的复选框值数组

<?= $form->field($model, 'country')->checkboxList(['FR'=>'France', 'DE'=>'Germany']) ?>

I need to insert the class="checkbox-inline"into the label tags of each checkbox generated by this yii2 helper method but I can not figure out how to do it.

我需要将 插入class="checkbox-inline"到这个 yii2 辅助方法生成的每个复选框的标签标签中,但我不知道该怎么做。

I was following these guides: checkboxListand checkbox one ( I can't post more than 2 links because I am new here ) but they are not helpful to me, I just do not understand what I have to do. Everything I tried just failed.

我正在遵循这些指南:checkboxList和 checkbox one(我不能发布超过 2 个链接,因为我是新来的)但它们对我没有帮助,我只是不明白我必须做什么。我尝试的一切都失败了。

Can someone help me please, I am trying for 3 days now ?

有人可以帮我吗,我现在正在尝试 3 天?

回答by soju

You should simply use :

你应该简单地使用:

<?= $form->field($model, 'country')->inline(true)->checkboxList(['FR'=>'France', 'DE'=>'Germany']) ?>

http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html#inline()-detail

http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html#inline()-detail