CakePHP: Displaying the correct label for lists and drop downs

A little way into my project, after setting up CakePHP and baking my MVC’s i hit a stumbling block. When i used viewed the edit and add forms, the drop downs just showed Numbers, the Id of each related item to be precise.

As you can see this isn’t much help.

The data is pulled in using the find(’list’) function. After trawling through the user groups I found that you can define which field is displayed when listed in the model ( which i probably should have seen in the manual, but it never occurred to me).

By adding the $displayField variable to a model and assigning the field name to it you can customise which fields is used:

[PHP] var $displayField = ‘Region’;[/PHP]

Tags: , , ,

You can leave a response, or trackback from your own site.

Leave a Reply