Disabling CSRF on a specific action CakePHP 3

后端 未结 4 1360
孤独总比滥情好
孤独总比滥情好 2021-01-06 18:38

So, I have a table that is auto-generated using DataTables. An action in my CakePHP grabs the data for that table, and formats it into JSON for datatables to use, this is th

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-06 19:15

    read all about the CSRF component here

    http://book.cakephp.org/3.0/en/controllers/components/csrf.html

    you can disable for a specific action here:

    http://book.cakephp.org/3.0/en/controllers/components/csrf.html#disabling-the-csrf-component-for-specific-actions

     public function beforeFilter(Event $event) {
         if (in_array($this->request->action, ['actions_you want to disable'])) {
             $this->eventManager()->off($this->Csrf);
         }
     }
    

提交回复
热议问题