将标签添加到复选框cakephp

时间:2015-02-23 07:08:12

标签: php cakephp label

我对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>

我几乎没事,但我想念small-text的课程label。有关如何实现这一点的任何想法?感谢名单!

2 个答案:

答案 0 :(得分:4)

使用下面的类来标记

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,因此它只显示文本。我添加了class参数,它指定了标签的类属性/属性。

答案 1 :(得分:0)

我更喜欢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提供的那个更好一些,因为它更紧凑,更易于阅读