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