我正在Bootstrap 3.0RC1使用CakePHP 2.3.6. 试图利用那些漂亮的类,比如has-error和has-warning用于验证状态,我需要更改FormHelper添加到包装 div 的默认元素类。
到目前为止,我正在使用此代码:
echo $this->Form->create('User', array(
'inputDefaults' => array(
'class' => 'form-control',
'div' => array('class' => 'form-group'),
'label' => array('class' => 'control-label'),
'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-block'))
)
));
echo $this->Form->input('email'));
这将在错误时输出:
<div class="form-group error">
<label for="UserEmail" class="control-label">Email</label>
<input name="data[User][email]" class="form-control form-error" type="email" value="a@a.com">
<span class="help-block">Email already in use.</span>
</div>
一切都很好,除了我需要将error包装 div 中的类更改为has-error,因此将新样式应用于label,input和span. 到目前为止找不到干净的解决方案。
has-error我认为丑陋的解决方案是将样式从 Bootstrap复制到error我的应用程序中的类。