Category Covered

CakePHP Display multiple fields in a single drop down find list

I want to show two fields value on the dropdown of cakephp which are retriving by find list query. For example i want to show first_name and last_name in my select dropdown.


Then use the folloing tested code.


$users= $this->User->find('all', array('conditions'=> array('User.is_doctor'=>1), 'fields'=>array('', 'User.first_name', 'User.last_name')));
$users = Set::combine($users, '{n}', array('%s %s', '{n}.User.first_name', '{n}.User.last_name'));

It wil return


yasir arafat
Adam Smith
Will Smith