我有一个使用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侦听器?提前谢谢。
答案 0 :(得分:1)
您应该在索引
上使用beforePaginate
https://crud.readthedocs.io/en/latest/actions/index.html#crud-beforepaginate