2012-08-09 99 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));