I am having a lot of difficulty understanding how to get my select box
to display properly. I have a table called owners and a related table
called buildings with the owner_id as the foreign key. I figured out
how cakephp looks for a field called name and then if it doesn't find
it will just default to listing the id in the option select box. What
I want to display is the last_name + "," + first_name and list them
alphabetically by last name.

I figured out that the find() command could help me accomplish this.
Using cake bake console I created the default controllers for
buildings and owners. In the add() and edit() functions in the
building controller, I found the following find() command:

$owners = $this->Building->Owner->find('list');

Using just this command pulls up the id only in the drop down. I am
trying to get the first and last name to show so I modified it to be:

$owners = $this->Building->Owner->find('list',
                   array('fields' =>
array('Owner.id','Owner.last_name','Owner.first_name')),
                   array('order' => array('Owner.last_name ASC'))
                   );

In the view file, I just have the following form command:

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

The result is kind of strange. I have 2 records for owners:
Mitch Friedman
Bob Miller

I am having somewhat of a success since the two owners are listed but
they are stacked on top of each other so the dropdown looks like this:
Mitch
Friedman
Bob
Miller

Anyone have any suggestions on how to at least get the names to
display properly? Ideally I would like to see  last_name + "," +
first_name but if I can end up with a normal looking list that isn't
stacked up like they are, that would be good enough.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" 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

Reply via email to