在CakePhp 3中,我有一个参数列表,我想在复选框中插入。我有这个代码
<?php
echo $this->Form->input('regions', [
'options' => $regions,
'value' => Hash::extract($ad->toArray(), 'regions.{n}.id'),
'class' => 'col-xs-4',
'type' => 'select',
'multiple' => 'checkbox',
'label' => false,
'error' => [
'attributes' => ['class' => 'col-xs-12 error-message inline']
],
]);
?>
没有出现col-xs-4类。我也插了
'div' => 'col-xs-4'
而不是上课。
我如何在每个复选框元素中插入一个类或div?
生成html:
<div class="input select">
<input type="hidden" name="regions" value="">
<div class="checkbox"><label for="regions-1"><input type="checkbox" name="regions[]" value="1" id="regions-1">Abruzzo</label></div>
<div class="checkbox"><label for="regions-2"><input type="checkbox" name="regions[]" value="2" id="regions-2">Basilicata</label></div>
<div class="checkbox"><label for="regions-3"><input type="checkbox" name="regions[]" value="3" id="regions-3">Calabria</label></div>
<div class="checkbox"><label for="regions-4"><input type="checkbox" name="regions[]" value="4" id="regions-4">Campania</label></div>
<div class="checkbox"><label for="regions-5"><input type="checkbox" name="regions[]" value="5" id="regions-5">Emilia Romagna</label></div>
<div class="checkbox"><label for="regions-6"><input type="checkbox" name="regions[]" value="6" id="regions-6">Friuli Venezia Giulia</label></div>
<div class="checkbox"><label for="regions-7"><input type="checkbox" name="regions[]" value="7" id="regions-7">Lazio</label></div>
<div class="checkbox"><label for="regions-8"><input type="checkbox" name="regions[]" value="8" id="regions-8">Liguria</label></div>
<div class="checkbox"><label for="regions-9"><input type="checkbox" name="regions[]" value="9" id="regions-9">Lombardia</label></div>
<div class="checkbox"><label for="regions-10"><input type="checkbox" name="regions[]" value="10" id="regions-10">Marche</label></div>
<div class="checkbox"><label for="regions-11"><input type="checkbox" name="regions[]" value="11" id="regions-11">Molise</label></div>
<div class="checkbox"><label for="regions-12"><input type="checkbox" name="regions[]" value="12" id="regions-12">Piemonte</label></div>
<div class="checkbox"><label for="regions-13"><input type="checkbox" name="regions[]" value="13" id="regions-13">Puglia</label></div>
<div class="checkbox"><label for="regions-14"><input type="checkbox" name="regions[]" value="14" id="regions-14">Sardegna</label></div>
<div class="checkbox"><label for="regions-15" class="selected"><input type="checkbox" name="regions[]" value="15" checked="checked" id="regions-15">Sicilia</label></div>
<div class="checkbox"><label for="regions-16"><input type="checkbox" name="regions[]" value="16" id="regions-16">Toscana</label></div>
<div class="checkbox"><label for="regions-17"><input type="checkbox" name="regions[]" value="17" id="regions-17">Trentino Alto Adige</label></div>
<div class="checkbox"><label for="regions-18"><input type="checkbox" name="regions[]" value="18" id="regions-18">Umbria</label></div>
<div class="checkbox"><label for="regions-19"><input type="checkbox" name="regions[]" value="19" id="regions-19">Valle d'Aosta</label></div>
<div class="checkbox"><label for="regions-20"><input type="checkbox" name="regions[]" value="20" id="regions-20">Veneto</label></div>
</div>
答案 0 :(得分:6)
最后,我决定:
<?php
echo $this->Form->input('Regions',
[
'templates' => [
'checkboxWrapper' => '<div class="col-xs-4 checkbox">{{label}}</div>',
],
'options' => $regions,
'value' => Hash::extract($ad->toArray(), 'regions.{n}.id'),
'type' => 'select',
'multiple' => 'checkbox',
'label' => false,
'error' => [
'attributes' => ['class' => 'col-xs-12 error-message inline']
],
]);
?>
此处的文档:http://book.cakephp.org/3.0/en/views/helpers/form.html#customizing-the-templates-formhelper-uses
答案 1 :(得分:0)
我会尝试传递div
选项。
<?php
echo $this->Form->input('regions', [
'div' => [
'class' => 'checkbox col-xs-4'
]
]);
?>
但您可能需要最终更改input field template。