I\'m new to Cake. I\'ve gotten some things set up, relevantly a \"users\" and a \"profiles\" table, controller, model and view. In my profiles/add
view, I\'m at
successfully set up the select to output the options from the user tables, but it uses the user.id as both the value and the option text.
find('list')
will by default use the primary key as the key, and the model's displayField
as the value.
If a model does not have an explicit displayField
but has a field named title
or name
Cake will automatically pick this field, otherwise it will not guess and simply use the primary-key field - which is what's happening in the question.
You can however simply specify which fields you want in the results of your find('list')
call. Therefore either:
class User extends AppModel {
public $displayField = 'username';
}
and then use:
$users = $this->User->find('list');
$users = $this->User->find('list', array(
'fields' => array('id', 'username')
));
In both cases - the result will be e.g.:
array(
1 => 'firstuser',
...
76 => 'AD7six'
)