我已经对以前的问题进行了彻底的审视,我很惊讶没有其他人问过这个问题,因为这看起来很简单.
如何使用CakePHP的FormHelper使标签包装输入和标签文本?我正在使用CakePHP 2.3.1.对$this->Form->radio()
某些标准选项的调用会产生:
<input id="input_id" type="radio" ... />
<label for="input_id">label text</label>
Run Code Online (Sandbox Code Playgroud)
我正在寻找的是
<label for="input_id"><input type="radio" id="input_id" ... />label text</label>
Run Code Online (Sandbox Code Playgroud)
我已经实现了这个类的使用:
$this->Form->input('input1',array('options'=>$options,'type'=>'radio',
'label'=>false
'before'=>'<label>',
'separator'=>'</label><label>',
'after'=>'</label>'
));
Run Code Online (Sandbox Code Playgroud)
但显然这种解决方案并不理想.任何人都可以告诉我,CakePHP是否有更简单,更"合适"的方式来实现这一目标?
har*_*ryg 14
我试图找到自己的答案并解决了这个问题.你不需要改变/扩展课程; 它可以通过传递适当的选项来实现.
这就是我所做的,所以它适用于bootstrap:
$options = array(
'1' => 'One',
'2' => 'Two'
);
$attributes = array(
'class' => '',
'label' => false,
'type' => 'radio',
'default'=> 0,
'legend' => false,
'before' => '<div class="radio"><label>',
'after' => '</label></div>',
'separator' => '</label></div><div class="radio"><label>',
'options' => $options
);
echo $this->Form->input('myRadios', $attributes);
Run Code Online (Sandbox Code Playgroud)
这将使每个无线电<div class="radio">
都符合引导标记.如果你只是想要简单的标签包装div
从中删除元素before
,after
和separator
归档时间: |
|
查看次数: |
3218 次 |
最近记录: |