CakePhp tip #5: Joining two fields to create one

Joining two fields to create one (eg to get somebodys name by combining firstname and surname)

cake-logo

You need to create a “VirtualField” in the model;

 public $virtualFields = array('fullname' => 'concat(Patient.firstname, "-", patient.surname)');

Then in your controller, to get a drop downlist;

 $patients = $this->Exercise->Patient->find('list',array('fields'=>array('fullname')));

Credit to:
http://stackoverflow.com/questions/11822942/cakephp-display-multiple-fields-in-a-single-drop-down