将标签添加到复选框 cakephp

add label to a checkbox cakephp

我对 CakePhp 有点陌生。 我有一个输入,它是一个带有标签的复选框,我想为标签分配一个 class。

这是我目前的情况:

echo $this->Form->input('', array(
               'type' => 'checkbox',
               'label' => 'I agree to the conditions',
               'separator' => '</div><div class="controls">',
               'format' => array('before', 'input', 'label','between', 'after','error'),

               ));

我想要的html是这样的:

<div class="control-group ">
            <div class="controls">
                <input type="checkbox" name="" id="" '> 
                <label class='small_text'> <!-- can't get this one in cake -->
                   I agree to the conditions
            </label>
            </div>
        </div>

我几乎没问题,但我想念 class small-text 因为 label。关于如何实现这一目标的任何想法?谢谢!

使用以下内容将 class 赋予标签

echo $this->Form->input('', array(
'type' => 'checkbox',
'label' => array('class' => 'small_text','text'=>'I agree to the conditions'),
'separator' => '</div><div class="controls">',
'format' => array('before', 'input', 'label','between', 'after','error'),

));

说明:'label' => array('class' => 'small_text','text'=>'I agree to the conditions'), 意味着您不仅要为标签提供文本,还要通过指定参数 class 为标签提供 class。默认情况下,根据您的代码,仅传递了文本,因此它仅显示文本。我添加了 class 参数,它为标签指定了 class property/attribute。

我更喜欢 jQuery.PHP.Magento.com 给出的那个,但我也会 post 我的解决方案.... 我想出了这样的事情:

$termsAndConditions =  $this->Html->link('Terms And Conditions', 'conditions', array('target' => '_blank'));

$labelConditions = $this->Form->label('agreeToConditions', 'I agree to the  '.$termsAndConditions.' of this site', array(
            'class' => 'small_text',
        ));

        echo $this->Form->input('agreeToConditions', array(
            'type' => 'checkbox',
            'label' => $labelConditions,
            'separator' => '</div><div class="controls">',
            'format' => array('before', 'input', 'label','between', 'after','error'),

            )); 
        ?>

我需要在问题中没有提到的标签中添加一个 link。

但是我认为 jQuery.php.Magento 提供的更好一些,因为它更紧凑且易于阅读