cakePHP’s find(’list’) function is used to generate a list of data (key=>value pairs) that can be used to populate select boxes easily.
A common requirement by most people is how to concatenate 2 fields in the display of the list (value) while still maintaining the key. For example, when displaying a list of users you may want to display the first name and last name while the key is the user id.
Currently, cakePHP’s find(’list’) function doesn’t support it. You can only specify a single field for a key and value.
I found this behaviour written by Daniel Albert (resshin) that will let you have multiple display fields http://bakery.cakephp.org/articles/view/multiple-display-field-3
I have used the customized version of this code (you can find it in the comments section of the link…written by Cosmin Cimpoi).
Just one tip: As Cosmin Cimpoi mentions you must ensure that recurive is atleast 0. In my case that didn’t work. For me recursive had to be set to atleast 1. But, I didn’t want recurive 1 to be used in other places so this is what I did:
$this->Address->find('list', array('recursive' => 1));
And it works like a charm!
