开发者

Conditional afterFind based on prefix or page

开发者 https://www.devze.com 2023-03-28 07:31 出处:网络
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 behav

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消