我正在使用cakephp formhelper,我想生成复选框
我希望cakephp生成像这样的复选框
<div class="form-group form-md-line-input">
<label class="col-md-2 control-label"
for="form_control_1">checkbox_title</label>
<div class="col-md-10">
<div class="md-checkbox-inline">
<div class="md-checkbox">
<input id="***this_part_should_be_match"
class="md-check"
type="checkbox">
<label for="***this_part_should_be_match">
<span></span>
<span class="check"></span>
<span class="box"></span>
</label>
</div>
</div>
</div>
</div>
此formhelper配置
[
'button' => '<button{{attrs}}>{{text}}</button>' ,
'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>' ,
'checkboxFormGroup' => '<label class="col-lg-2 control-label">{{label}}</label><div class="col-md-10"> <div class="md-checkbox-list"><div class="md-checkbox"><input id="{{id}}" class="md-check" type="checkbox">
<label for="{{id}}">
<span></span>
<span class="check"></span>
<span class="box"></span></label></div></div></div>' ,
'checkboxWrapper' => '<div class="">{{label}}</div>' ,
'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}' ,
'error' => '<div class="error-message">{{content}}</div>' ,
'errorList' => '<ul>{{content}}</ul>' ,
'errorItem' => '<li>{{text}}</li>' ,
'file' => '<input type="file" name="{{name}}"{{attrs}}>' ,
'fieldset' => '<fieldset{{attrs}}>{{content}}</fieldset>' ,
'formStart' => '<form class="form-horizontal" {{attrs}}><div class="form-body">' ,
'formEnd' => '</div> </form>' ,
'formGroup' => '{{label}}<div class="col-md-10">{{input}}<div class="form-control-focus"> </div></div>' ,
'hiddenBlock' => '<div style="display:none;">{{content}}</div>' ,
'input' => '<input class="form-control" type="{{type}}" name="{{name}}"{{attrs}}/>' ,
'inputSubmit' => '<input type="{{type}}"{{attrs}}/>' ,
'inputContainer' => '<div class="form-group form-md-line-input">{{content}}</div>' ,
// 'inputContainer' => '<div class="input {{type}}{{required}}">{{content}}</div>' ,
'inputContainerError' => '<div class="input {{type}}{{required}} error">{{content}}{{error}}</div>' ,
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>' ,
'nestingLabel' => '{{hidden}}<label{{attrs}}>{{input}}{{text}}</label>' ,
'legend' => '<legend>{{text}}</legend>' ,
'multicheckboxTitle' => '<legend>{{text}}</legend>' ,
'multicheckboxWrapper' => '<fieldset{{attrs}}>{{content}}</fieldset>' ,
'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>' ,
'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>' ,
'select' => '<select class="form-control" name="{{name}}"{{attrs}}>{{content}}</select>' ,
'selectMultiple' => '<select name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>' ,
'radio' => '<input type="radio" name="{{name}}" value="{{value}}"{{attrs}}>' ,
'radioWrapper' => '{{label}}' ,
'textarea' => '<textarea class="form-control" name="{{name}}"{{attrs}}>{{value}}</textarea>' ,
'submitContainer' => '<div class="">{{content}}</div>' ,
]
目前它生成了这个
<div class="form-group form-md-line-input">
<label class="col-lg-2 control-label">
<input class="form-control"
name="active"
value="0"
type="hidden">
<label for="active">
<input name="active"
value="1"
id="active"
checked="checked"
type="checkbox">
Active
</label>
</label>
<div class="col-md-10">
<div class="md-checkbox-list">
<div class="md-checkbox">
<input id=""
class="md-check"
type="checkbox">
<label for="">
<span></span>
<span class="check"></span>
<span class="box"></span></label>
</div>
</div>
</div>
</div>
我想知道我的配置应该是什么才能让cakephp生成我想要的chekbox
在主题中我正在使用id =&#34; *** this_part_should_be_match&#34;并为=&#34; *** this_part_should_be_match&#34;应正确显示
我使用的是cakephp 3.5,但我认为它应该与3相同。* 我会感激任何帮助
答案 0 :(得分:0)
将此添加到配置
'checkboxContainer' => '<div class="form-group form-md-line-input"><label class="col-md-2 control-label" for="form_control_1">{{title}}</label>
<div class="col-md-10">
<div class="md-checkbox-inline">
<div class="md-checkbox">
{{content}}{{label}}
<span></span>
<span class="check"></span>
<span class="box"></span>
</label>
</div>
</div>
</div>
</div>'
生成复选框
时,您必须使用templateVars
选项设置标题
$this->Form->control('some_checkbox', ['type' => 'checkbox', 'templateVars' => ['title' => 'checkbox_title']);