2015-02-23 148 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提供的一個好一點,因爲它是更緊湊,更易於閱讀