class IncidentsController extends AppController {
...
function add() {
...
$users = $this->Incident->User->find('all',
array('fields' => array('id','lastname','firstname')), 0);
$users = Set::combine($users,
'{n}.User.id', /* key */
array('{0}, {1}', /* formatting, note the comma in the middle */
'{n}.User.lastname','{n}.User.firstname')); /* mapping to the format */
...
$this->set(compact('users', ... )); /* if it has just $this->set('foo'); replace with compact */
}
...
Repeat those $users lines as often as you need to pass it to $this->set(); however, I would create a local private function and call the private function.
...
function __genUserList() {
$users = $this->Incident->User->find('all',
array('fields' => array('id','lastname','firstname')), 0);
$users = Set::combine($users,
'{n}.User.id',
array('{0}, {1}','{n}.User.lastname','{n}.User.firstname'));
return $users;
}
...
function add() {
...
$users = $this->__genUserList();
$this->set(compact('users', ... ));
}
...
