我正在cakePHP中设置用户注册表单,inputDefaults
用于匹配水平表单的twitter引导程序要求
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)));
您基本上将“覆盖”,但仍保留默认选项。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句