Thanks b logica - I'm getting closer :)

I had to change the line above to this:
    $this->set('brigades', $this->Member->Brigade->findAll());
I now have the $brigades variable available in my view as an array:
    [0] => Array
        (
            [Brigade] => Array
                (
                    [id] => 1
                    [name] => Town A
                )

            [Member] => Array
                (
                )

        )

    [1] => Array
        (
            [Brigade] => Array
                (
                    [id] => 2
                    [name] => Town B
                )

            [Member] => Array
                (
                )

        )

But I can't figure out how to get this in to a format suitable for the
HtmlHelper. Are we running different versions of CakePHP? Because I'm
using the HtmlHelper to build my forms:
           <?php echo $html->selectTag('Member/brigade_id',
compact($brigades), null, array(), true) ?>   <!-- THIS DOESN'T WORK --
>
           <?php echo $html->tagErrorMsg('Member/brigade_id', 'Please select
a brigade.') ?>
But you were using the FormHelper? Is FormHelper better? Should I use
that instead? I'm only using the HtmlHelper because that's what was
used in the tutorial :)

Cheers,
~p

On Apr 8, 5:38 am, "b logica" <[EMAIL PROTECTED]> wrote:
> 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/fb6b71db...
>
> >  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 cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to