Tuesday, February 22, 2011

Re: problems populating my select box

try:

$charities = $this->Campaign->Charity->find('list', array('fields' => array('Charity.id', 'Charity.charity_name')));

And then

echo $this->Form->input('Charity.charity_name', array('options' => $charities));

(It would automatically select the columns "id" and "name" but I think if they are different you need to specify, I may be wrong).

On 22 February 2011 14:49, barricades <davowave@googlemail.com> wrote:
Hi there, newbie here.

I have a campaign model and a charity model. Campaign belongsTo
Charity and Charity hasMany Campaigns.

I have a form which creates a campaign and I need a select box to have
the name of all the charities. What I have at the minute is what cake
baked for me and it creates a select box for the charities but it has
their ids rather than the charity's name.

From the documentation I changed it to:

in the controller:
$users = $this->Campaign->User->find('list');
$charities = $this->Campaign->Charity->find('list');
$this->set(compact('users', 'charities'));

in the view:
echo $this->Form->input('Charity.charity_name');

(I also tried)
echo $this->Form->input('Charity', array('type'=>'select',
'options'=>'$charities'));

but I can get neither to work. I've googled and not found an answer I
understand.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php



--
Kind Regards
 Stephen @ NinjaCoderMonkey

 www.ninjacodermonkey.co.uk


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: