CakeFp 3.x Crud插件beforeFind事件不可用

时间:2018-01-02 20:20:16

标签: rest api cakephp listener cakephp-3.0

我有一个使用CRUD插件的Cakephp 3.x API。 这是我的crud配置:

$this->loadComponent('Crud.Crud', [
            'actions' => [
                'Crud.Index',
                'Crud.View',
                'Crud.Add',
                'Crud.Edit',
                'Crud.Delete'
            ],
            'listeners' => [
                'Crud.Api',
                'Crud.ApiPagination',
                'Crud.ApiQueryLog'
            ]
        ]);

在我的控制器中,当我调用它 - > Crud-> implementedEvents()时,它返回beforeFilter startuperxot beforePaginate

public function index(){
    $this->Crud->implementedEvents(); //returns beforeFilter startuperxot beforePaginate
    $this->Crud->on('beforeFind', function(\Cake\Event\Event $event) {
        if(isset($this->request->query['state'])){
            $event->getSubject()->query->where(['state =' => $this->request->query['state']]);
        }
    });
    return $this->Crud->execute();
}

如何启用beforeFind侦听器?提前谢谢。

1 个答案:

答案 0 :(得分:1)