Make Select Options Static to Dynamic

2019-09-21 19:22发布

问题:

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

Right now is static. as per below line

<?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'
                            )
                        );
?>

My static field output https://www.dropbox.com/s/6133d4e9aorpo33/Selection_047.png?dl=0

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

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

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);

and in ctp i used

'options' => $time

回答1:

In ctp

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

UPDATED solution

In controller:

NEW

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

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

////INSIDE model

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