doutan2111 2016-04-04 18:34
浏览 85
已采纳

CakePHP 3.x ORM get(),find()以及如何禁用befeoreFind()?

I use the beforeFind() callback with some conditions that must be apply in most case, but not in all. And the quesion is about this.

What are the right way for disable the beforeFind() callback?

At the moment i use this approach:

in beforeFind() i have a return $query if options default are false

if(isset($options['default']) && $options['default'] == false){
    return $query;
}

And now when i perform a find() operation, i can disable by set default option to false

$this->Articles->find()->applyOptions(['default' => false])...

But when i use get() method, i don't know how to do...

i can use findById() and applyOptions again but if there are another way i prefer.

Thanks in advance!

  • 写回答

2条回答 默认 最新

  • douchuifk90315 2016-04-05 10:12
    关注

    Just use

    $this->Hotels->get($id, ['default' => false]); 
    

    $options will be passed and your beforeFind will keep working :-D

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?