compact() ... compacts an array, essentially. But you don't need that, i think.
add this to your MembersController::edit() method:
$this->Member->Brigade->displayField = 'name';
$this->set('brigades', $this->Member->Brigade->find('list'));
This creates a variable, $brigades, which you can use in your view.
The find('list') will return an array that's already formatted for
dropping into a select list.
The first line is redundant, as it is, because Cake will use the
"name" column when performing the find('list'). If your table does not
use a column called "name" for whatever you'd like displayed in the
select list, pass that column name to the displayField variable as
shown above.
an example for your edit.ctp:
<?= $form->label('Member.brigade_id', '* Brigade', array('class' =>
'Required')) ?>
<?= $form->select('Member.brigade_id', $brigades, null, array(), true) ?>
<?= $form->error('Member.brigade_id', 'Please select a brigade.') ?>
On Mon, Apr 7, 2008 at 2:58 AM, fukawi2 <[EMAIL PROTECTED]> wrote:
>
>
> http://groups.google.com/group/cake-php/browse_thread/thread/fb6b71db2de8392d/7fe9e8fa9252f234
>
> I realize this may be a bit of a sore point (after reading the post
> above) but I think I'm retarded and missing something obvious... Bare
> with me please - this is my second day using any PHP Framework.
>
> I'm writing a webapp to keep track of members and training records etc
> for fire brigades. I have a table of Members (fire fighters) and a
> table of Brigades. Each member belongsTo a Brigade (I have that
> relationship setup in my Model).
>
> On my members/edit view, I need a select list for all the Brigades in
> the database, but I can't figure out how to do it. Looking at the post
> I linked at the top of this, I need to do something along the lines
> of:
> $brigades = $this->Brigade->find('name');
> $this->set(compact('brigades'));
>
> I don't understand the second line, and I don't know where I should be
> putting that. I tried putting it in my edit function in the Members
> Controller, but it throws me back an Undefined Property error.
>
> I understand that the current value ONLY will be passed in the POST,
> but I just can't figure out how to build the rest of the options from
> the values in the Database table.
>
> Can someone please point me back on track?
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---