CakePHP Form Dropdown -


i've got table in database outputs this:

array( (int) 0 => array(     'price' => array(         'id' => '1',         'amount' => '20',         'price' => '180.00',         'type_id' => '1',         'active' => 'a'     ) ), (int) 1 => array(     'price' => array(         'id' => '2',         'amount' => '30',         'price' => '232.50',         'type_id' => '1',         'active' => 'a'     ) ),  

...and on.

i need drop down in form displays amount , price (ie. "20 @ 180.00"), when selected, gets "id" field.

i reworked new array called $prices outputs so...

array( (int) 0 => array(     'id' => '1',     'amount' => '20',     'price' => '180.00',     'type_id' => '1',     'active' => 'a',     'display' => '20 @ 180.00' ), (int) 1 => array(     'id' => '2',     'amount' => '30',     'price' => '232.50',     'type_id' => '1',     'active' => 'a',     'display' => '30 @ 232.50' 

however, i'm not sure if array necessary.

but main problem don't know put in form options make select "display" field.

echo $this->form->input('project.quantity', array(   'options' => $prices[?????]['display'] )); 

simply adding

'options' => $prices 

displays lot of stuff in drop down (http://f.cl.ly/items/1e0x0m0d1f1c2o3k1n3h/screen%20shot%202013-05-08%20at%201.13.48%20pm.png).

is there better way of doing this?

you can use virtual fields.

in model:

public $virtualfields = array(   'display' => 'concat(amount, " @ ", price)' ); 

in controller:

$prices = $this->price->find('list', array(   'fields' => array('id', 'display') )); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -