选择静态到动态选项

时间:2014-11-03 05:10:40

标签: html cakephp cakephp-2.0 cakephp-2.3

选择的选项值是静态的&我想要它动态

现在是静态的。如下线

<?echo $this->Form->input('intaddressid', 
                            array(
                                'options' => 
                                    array('add1static,add1static' => 'add1static,add1static',
                                          'addres2static,add2stattic'=>'addres2static,add2stattic'),
                                'label'=>false,
                                'empty' => '(Select hotel and time)',
                                'class' => 'form-control border_none'
                            )
                        );
?>

我的静态字段输出 https://www.dropbox.com/s/6133d4e9aorpo33/Selection_047.png?dl=0

如果我为每个人设定了我的动态 https://www.dropbox.com/s/v3hfhfaubkfr62m/Selection_048.png?dl=0

但我希望它只在1个字段中所有值,所以帮助它

我每次都使用时间和我的表值生成但现在我希望这个值在我的静态代码之上。 value =&gt; add1,add2 = add1,add2

$times['Time']['varaddress1'] $times['Time']['varaddress2']

我的更新代码是 - &gt;

$arr1=array();

$arr2=array();

$arr1 = $this->Time->find('list', array( 'fields' => array('varaddress1'),'order'=> array('Time.varaddress1') ));

$arr2 = $this->Time->find('list', array( 'fields' => array('varaddress2'),'order'=> array('Time.varaddress2') ));

$finalArr=array_merge ($arr1,$arr2);

$this->set('time',$finalArr);

在ctp我使用

'options' => $time

1 个答案:

答案 0 :(得分:0)

在ctp中

               <?php
                    echo $this->Form->input('intaddressid', array(
                    'options' => $courseCategoriesNames,
                    'empty' => '(choose one)',
                    'label' => false
                    ));
                ?>  

更新解决方案

在控制器中:

$arr1=array();
$arr2=array();

    $arr1= $this->Course->CourseCategory->find('list',
                                                        array('fields'=> array('Time.varaddress1'),
                                                              'order'=> array('Time.varaddress1')                                                                                                                                                                                                    )
                                            );


$arr2= $this->Course->CourseCategory->find('list',
                                                        array('fields'=> array('Time.varaddress1'),
                                                              'order'=> array('Time.varaddress2')                                                                                                                                                                                                    )
                                            );

    $finalArr=array_merge ($arr1,$arr2);
    $this->set('courseCategoriesNames',$finalArr);

FINAL ans // INSIDE模型你的时间 - &gt;

public $virtualFields = array('name_price' => 'concat(Time.varaddress1, "-", Time.varaddress2)');

//// INSIDE模型

$products=$this->Product->find('list',array('fields'=>  $this->Time->virtualFields['name_price'] )));
$this->set('products',compact($products));