Using Virtual Fields in CakePhp
September 6th, 2010 | CakePhpVirtual fields in cakephp are used as an alias in sql expressions. Alias is used to give a column a different name.
Example, to concatenate fields,
class Applicant extends AppModel {
var $name = 'Applicant';
var $virtualFields = array( 'name' => "CONCAT(Applicant.firstname, ' ', Applicant.lastname)" );
}
To access the virtual field
$this->Applicant->find( 'first', array( 'fields' => array( 'name' ) ) );