gpt4 book ai didi

cakephp - 使用 cakephp 3.x 设置类或 div 复选框表单

转载 作者:行者123 更新时间:2023-12-02 08:29:15 24 4
gpt4 key购买 nike

在 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&#039;Aosta</label></div>
<div class="checkbox"><label for="regions-20"><input type="checkbox" name="regions[]" value="20" id="regions-20">Veneto</label></div>
</div>

最佳答案

最后,我解决了:

<?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

关于cakephp - 使用 cakephp 3.x 设置类或 div 复选框表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29030606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com