开发者

how to disable security component for certain actions in cakephp?

开发者 https://www.devze.com 2023-03-30 18:50 出处:网络
I have a form 开发者_如何学JAVAin my add_note action, where I do not want SecurityComponent to put its tokens or checking. How do I do this?

I have a form 开发者_如何学JAVAin my add_note action, where I do not want SecurityComponent to put its tokens or checking. How do I do this?

I have tried requireAuth('some_other_action') etc. but it doesn't work.


In CakePhp 2.3 do:

$this->Security->unlockedActions= array('add_note');


Original answer for CakePHP 1.2 to 2.2.x:

public function beforeFilter() {
    if (isset($this->Security) && $this->action == 'add_note') {
        $this->Security->validatePost = false;
    }
}

Updated answer for CakePHP 2.3+ and 3.x (as pointed out in the other answer):

public function beforeFilter(Event $event)
{
     $this->Security->config('unlockedActions', ['add_note']);
}

Also, it's possible to unlock specific fields (as pointed out in the comments)

$this->Form->unlockField('Note.id');
0

精彩评论

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