选择静态到动态选项 [英] Make Select Options Static to Dynamic

查看:234
本文介绍了选择静态到动态选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Select's Option Values are static & i want it dynamic

现在是静态的。

<?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

And if i set for each then my dynamic https://www.dropbox.com/s/v3hfhfaubkfr62m/Selection_048.png?dl=0

但我想要只有在1字段所有的值所以帮助它

But i want it only in 1 field all value so help on it

我用于每次作为时间和我的表值生成,但现在我想要这个值在我的静态代码。 value => add1,add2 = add1,add2

I used for each times as time and my table value generated but now i want this value in above my static code. value => add1,add2 = add1,add2


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

我更新的代码是 - >

my updated code is ->

$ 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 i中使用

'options'=> $ time

推荐答案

Inctp

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

UPDATED解决方案

在控制器中:

$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 model Your Time->

FINAL ans //INSIDE model Your Time->

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

//// INSIDE模型

////INSIDE model

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

这篇关于选择静态到动态选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆