Farhad Farhad - 5 months ago 14
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

thanks

Answer

Add the following to your model:

public function afterFind($results, $primary = false){
    foreach ($results as $key => $val) {
        unset($results[$key][$this->alias]['password']);
    }

    return $results;
}

This should also work:

public function afterFind($results, $primary = false){
    return Hash::remove($results, '{n}.'.$this->alias.'.password');
}