Add virtual field in cakephp 2.* in find methods

Author - Kailash
15.03.2017
|
0 Comments
|

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',
    array(
        'fields' => array(
            'ModelName.virtual_field_name', //user virtual field
            'ModelName.deleted',
        )
    )); 	 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 dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *