Conditional afterFind based on prefix or page
I have a behavior with an afterFind function that I 开发者_运维百科only want called on a non-admin prefix. $this->params does not work, since $this is referencing the behavior. How can I make this behavior conditional based on the page or prefix?
you can detach (or disable) behavior in the controller:
function beforeFilter(){ if($this->params['admin'])$this->Model->Behaviors->detach('Foo'); }
http://book.cakephp.org/view/1072/Using-Behaviors
Or you can add your own behavior keyword (like 'contain' for Containable) in the find.
精彩评论