2015-02-23 127 views
1

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

我得到了几乎所有的权利,但我错过了类small-textlabel。任何想法如何实现?感谢名单!

这给类

回答

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

+1

谢谢大家,也为明确的解释! – mikey 2015-02-23 08:01:08

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提供的一个好一点,因为它是更紧凑,更易于阅读