Issue
I have a Model named Users with a virtual field named full_name, and it works fine in the template by calling:
<?= $user->full_name; ?>
But it doesn't automatically come to the REST.
Solution
Quote from the docs:
By default virtual properties are not exported when converting entities to arrays or JSON. In order to expose virtual properties you need to make them visible. When defining your entity class you can provide a list of virtual properties that should be exposed:
namespace App\Model\Entity; use Cake\ORM\Entity; class User extends Entity { protected $_virtual = ['full_name']; }This list can be modified at runtime using
virtualProperties:$user->virtualProperties(['full_name', 'is_admin']);
Cookbook > Database Access & ORM > Entities > Exposing Virtual Fields
Answered By - ndm
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.