Add virtual field in cakephp 2.* in find methods

Author - Kailash

How to specify an extra field (not existing in the table) while fetching data from database using find method? Solution is explained below.

Assign value to virtual field before find function call:

$this->virtualFields['virtual_field_name'] = 'any value';

Use virtual field in find function:

$result = $this - > find('all',
        'fields' => array(
            'ModelName.virtual_field_name', //user virtual field
    )); 	 unset($this->virtualFields[‘virtual_field_name’]);
Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published.