Tried it and it works great! Thanks.
On Dec 17, 5:26 pm, cricket <zijn.digi...@xxxxxxxxx> wrote:
> On Fri, Dec 17, 2010 at 6:25 PM, eldorado2768
> <davidbrotman2...@xxxxxxxxx> wrote:
> > 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.
> You can create a virtual field in the model.
> public $virtualFields = array(
> 'full_name' => 'CONCAT(User.last_name, ", ", User.first_name)'
> Then, I believe (haven't tried this) that you could specify full_name
> as the model's display field:
> public $displayField = 'full_name';
> $owners = $this->Building->Owner->find(
> 'order' => array('Owner.last_name' => 'ASC')
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
To post to this group, send email to cake-php@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
cake-php+unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at