Call __get on Entity


#1

I’m trying to change my Customers-Entity to comply with GDPR.
When a custumer is set to “inactive” the properties should be displayed as ‘*****’.
Now, when I#m using find() in my controller and prase it as a JSON, the properties are still visible.
Only a virtual property is hidden correctly.
How can I make sure, the __get Method is called for each entity. Or any other solution for this problem?

Here is my code of the Entity
public function &__get($s) {
if ($this->_properties[‘inactive’]) {
return ‘*****’;
} else {
if ($s == “full_name”) {
return $this->_properties[‘name’] . ', ’ . $this->_properties[‘firstname’];
} else {
return $this->_properties[$s];
}
}
}

An the code from the controller

$this->loadmodel('Customers');
        $customers = $this->Customers->find()->order('name, firstname')->where('id > 1000');
        /*
        foreach ($customers as $customer) {
            $customer['fullname'] = $customer->fullname;
        }
        $this->set('customers', $customers);
        $this->set('_serialize', 'customers');*/

        echo json_encode($customers);
        die;