Farhad Farhad - 1 year ago 89
PHP Question

cakephp - triggered - after the execution of the query

How can change output one of model in all queries?

This means that queries run on this model, then go to a specific function.

for example, in user model, how remove password field for all queries


Answer Source

Add the following to your model:

public function afterFind($results, $primary = false){
    foreach ($results as $key => $val) {

    return $results;

This should also work:

public function afterFind($results, $primary = false){
    return Hash::remove($results, '{n}.'.$this->alias.'.password');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download