Cakephp表单单选按钮标签类

Cakephp表单单选按钮标签类,cakephp,radio-button,label,cakephp-2.0,Cakephp,Radio Button,Label,Cakephp 2.0,我想使用单选按钮使用表单帮助器。单选按钮具有单选元素和标签。默认情况下,我有标签元素的显示:块。我想在单选按钮的标签上指定一个类,这样我就可以为它指定一个内联块 $attributes = array('legend' => false, 'label' => array('class' => 'radioBtn')); echo $this->Form->radio('gender', $options, $attributes); 如何通过查看Form->r

我想使用单选按钮使用表单帮助器。单选按钮具有单选元素和标签。默认情况下,我有标签元素的显示:块。我想在单选按钮的标签上指定一个类,这样我就可以为它指定一个内联块

$attributes  = array('legend' => false, 'label' => array('class' => 'radioBtn'));
echo $this->Form->radio('gender', $options, $attributes);

如何通过查看Form->radio()方法代码,将类分配给选项的标签,似乎与属于标签的属性没有任何关系

但是要修改这些标签的显示,可以使用周围的
div

echo '<div class="inline_labels">';
echo $this->Form->radio('gender', $options, $attributes);
echo '</div>';

使用
FormHelper::label(string$fieldName、string$text、array$options)怎么样
您可以在选项数组中定义标签类,因此(例如):

来源

为我工作:

//  Add your own label with CSS class
$opts = array('1' => "<label class='myCSS'>My first option</label>", "2" => "<label class='myCSS'>My second option</label>");

//  Put label param to false
echo $this->Form->input('my-input', array('type' => 'radio', 'label' => false, 'options' => $opts, 'legend' => false));
//使用CSS类添加您自己的标签
$opts=array('1'=>“我的第一个选项”,“2”=>“我的第二个选项”);
//将标签参数设置为false
echo$this->Form->input('my-input',array('type'=>'radio','label'=>false,'options'=>$opts,'legend'=>false));

享受

是的,标签现在很好地放在一行上。唯一糟糕的是,他们失去了与单选按钮的连接。
echo $options = array( /* relevant stuff goes here */ );
echo $attributes = array( /* relevant stuff goes here */ );
echo $this->Form->radio('gender', $options, $attributes);
echo $this->Form->label('gender', 'Text of your label', array('label'=>'radioBtn'))
//  Add your own label with CSS class
$opts = array('1' => "<label class='myCSS'>My first option</label>", "2" => "<label class='myCSS'>My second option</label>");

//  Put label param to false
echo $this->Form->input('my-input', array('type' => 'radio', 'label' => false, 'options' => $opts, 'legend' => false));