2012-08-09 157 views
3

如何添加額外的屬性到我的選擇菜單選項標籤?像這樣:CakePHP 1.3 - 添加額外的屬性來選擇菜單選項

<select class="test" name="data[Test][test]"> 
    <option value="1" data-price="100">My Option</option> 
</select> 

如何添加data-price="100"

我想是這樣的,但它沒有工作:

<?php 
    echo $this->Form->select('test', $options, null, array(
     'class' => 'test', 
     'options' => array(
      'data-price' => 100 
     ) 
    )); 
?> 
+0

這個幫助你? http://phppoet.blogspot.in/2012/07/cakephp-date-field-with-default-values.html – jack 2012-08-15 08:28:49

回答

0

您必須手動構建選擇HTML

也可以參考How to give select tag an attribute in cake php?

+0

你在哪裏工作先生? – 2012-08-09 12:20:26

+0

在同一家公司:) – 2012-08-09 16:43:40

+0

哈哈:D很高興在這裏見到你:) – 2012-08-13 04:02:21

3
you can try this 
    echo $this->Form->input('test', array(
         'options' => array(
              1=>array(
              'data-price' => 100, 
              'value' => '1', 
              'name' => 'My Option' 
             )),'class' => 'test') 
            ); 
1

你可以這樣來做:

$options = array(
    ... 
    array('name' => 'United states', 'value' => 'USA', 'title' => 'the title that you want', 'class' => 'something'), 
    array('name' => 'USA', 'value' => 'USA', 'title' => 'the other title that you want', 'class' => 'otherthing'), 
); 

echo $this->Form->input('test', array('type'=>'select', 'options'=>$options));