$swimmer = $this->Swimmer->find('list', array(
'condition开发者_如何学Pythons' => array('Swimmer.group' => $this->data['Swimmer']['group_id']),
'order' => array('Swimmer.first_name ASC'),
'fields' => 'Swimmer.first_name'
));
First of all, setup a virtual field in your Swimmer model as suggested by Ann Pham. eg:
var $virtualFields = array(
'name' => "CONCAT(Swimmer.first_name, ' ', Swimmer.last_name)"
);
Then, fetch the data for your dropdown list like so: (assuming Swimmers controller)
$this->Swimmer->find('list', array('fields' => array('Swimmer.id', 'Swimmer.name')));
You could also try doing this in your SwimmerModel: var $displayName = 'Swimmer.name';
(not 100% sure if this would work). If it does work, you won't need the 'fields' array in the find.
An another approach is to concat the field on the fly in the fields list.
Ex:
$swimmer = $this->Swimmer->find('list',
array(
'conditions' => array(
'Swimmer.group' => $this->data['Swimmer']['group_id']),
'order' => array(
'Swimmer.first_name ASC'
),
'fields' => 'CONCAT(Swimmer.first_name, " ", Swimmer.first_name) AS full_name'
));
http://book.cakephp.org/view/1588/virtualFields
精彩评论