tags:

views:

329

answers:

1

hi all, am a newbie in cakephp. i need to get values from the DB & populate it in the view. from all the forums i have visited, i came to know that generateList() has been deprecated. if so, what do i need to use. where shud i place these codes.could any of u guys explain me the code part.

+2  A: 

in you controller action for the view containing the list:

$associatedItems = $this->Item->AssociatedItem->find('list');
$this->set(compact('associatedItems'));

Change items and associated items for your actual model names.

The find('list') method returns an array of id => displayField pairs, e.g. for Posts with a title field, it will return an array like (1 => 'My first post') etc. See the cook book page for retrieving data from your models for more information.

The Cake Form helper, when you call

echo $form->input('associated_item_id');

will detect there is a variable available in the view called associatedItems and render a select tag with the contents of $associatedItems as the options.

neilcrookes
Thank u Neil. worked like a charm for me. :)
Naveen