gpt4 book ai didi

forms - cakePHP 表单输入标签覆盖 inputDefaults

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

我正在 cakePHP 中设置用户注册表单,使用 inputDefaults匹配 horizontal forms 的 Twitter bootstrap 要求

    echo $this->Form->create('User', array(
'class' => 'form-horizontal',
'role' => 'form',
'inputDefaults' => array(
'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
'div' => array('class' => 'form-group'),
'label' => array('class' => 'col-sm-2 control-label'),
'between' => '<div class="col-sm-10">',
'after' => '</div>',
'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-inline')),
)));

在里面,我正在使用
echo $this->Form->input('username');

显示表单元素。

我想要自定义标签,如下所示:
echo $this->Form->input('username', array('label' => 'Benutzername'));

不幸的是,这会覆盖我的默认设置。如何一次使用默认设置和自定义标签,而不重新定义所有输入元素的所有设置?

最佳答案

我会这样做

$mainLabelOptions = array('class' => 'col-sm-2 control-label');
echo $this->Form->create('User', array(
'class' => 'form-horizontal',
'role' => 'form',
'inputDefaults' => array(
'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
'div' => array('class' => 'form-group'),
'label' => $mainLabelOptions,
'between' => '<div class="col-sm-10">',
'after' => '</div>',
'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-inline')),
)));

//then I would create a new label options array and have it merged to the main one
$myLabelOptions = array('text' => 'Benutzername');
echo $this->Form->input('username', array('label' => array_merge($mainLabelOptions, $myLabelOptions)));

您基本上会“覆盖”但仍保持默认选项。

关于forms - cakePHP 表单输入标签覆盖 inputDefaults,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21740063/

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