TOPICS

FIND YOUR TOPIC QUICKLY

CakePHP: Multiple Fields in find(’list’)

Oct 03 2008

Keith Medlin

One of my biggest gripes with CakePHP is that there isn’t a built in way to easily define how models report back their “name” to views.  There is a handy variable called $displayField, but currently (1.2 RC3) that only accepts a single field.

var $displayField = 'last_name';

That’s not particularly useful in a user management console where you need to display both first and last names, and potentially an e-mail address or username in a form.

Let’s use a concrete example…

You are working on an application to assign tasks to members within your team.  In your task creation view you want to have a dropdown with the 5 other people in your team, but find(’list’) is only displaying the primary key of the users and not their names.

The solution is provided quite elegantly by Teknoid here: http://teknoid.wordpress.com/2008/09/04/findlist-with-three-or-combined-fields/

Please check it out and thank him for the great writeup that respects the CakePHP core functionality while usefully extending a part of the CakePHP code that really needs to be reconsidered.

Leave a Reply





You can use basic HTML styling tags such as bold or italics. Other markup will be removed when you submit your post.

RECENT COMMENTS




  • ON...CakePHP 1.2 File Upload
    "Fixed it! Thanks for the heads up Jose."
  • Keith Medlin
  • ON...CakePHP 1.2 File Upload
    "Thanks a lot for the example. Just another typo/error in the tutorial : var $validateFile = array( ’size’ = 204800, should be: var $validateFile = array( ’size’ => 204800,..."
  • Jose Sanchis