Ian Hunter
Ian Hunter

Reputation: 9774

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?

Upvotes: 0

Views: 199

Answers (1)

Anh Pham
Anh Pham

Reputation: 5481

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.

Upvotes: 1

Related Questions