将标签添加到复选框cakehp


add label to a checkbox cakephp

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

以下是我目前所拥有的:

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>

我几乎没事,但我错过了labelsmall-text课。你知道如何做到这一点吗?thanx!

使用下面的方法,将类标记为

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为标签提供类。默认情况下,根据您的代码,只传递了Text,因此它只显示文本。我添加了类参数,它指定了标签的类属性。

我更喜欢jQuery.PHP.Magento.com提供的解决方案,但我也会发布我的解决方案。。。。我想出了这样的东西:

$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'),
            )); 
        ?>

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

然而,我认为jQuery.php.Magento提供的版本要好一点,因为它更紧凑,更容易读取