tags:

views:

1374

answers:

3

Does anybody know how to select the contents of one take from a different view in cakephp.

I have a take itemgroups that has 2 fields ID and Description. I need to make a down down list in the item add page but I can not find a good way to get all of the values from another table into an array to put into the page.

Below I have also listed my models for each.

array('rule' => 'notEmpty'),'description' => array('rule' => 'notEmpty')); } ?>

A: 

Here is the code to display a select dropdown.

<?php echo $form->input('inputname', array('type'=>'select', 'options'=>$cate, 'label'=>false, 'empty'=>'Category')); ?>

where $cate is loaded with an array from a find('list') in the format

array(0 => 'option1', 1=>'option2', etc etc etc

+2  A: 

Assuming your model is User and the field you want to use is a list of US states (for example)...

In your controller:

$this->set('states',$this->State->find('list'));

and in your view:

<?php echo $form->input('User.state',array('type'=>'select','options'=>$states)); ?>
inkedmn
A: 

If it's something like a "US States" dropdown list that is going to be repeated from page to page, consider using an Element, which you can just pass data to and you won't have to repeat all the UI code again.

mgroves