如何在cakephp中禁用某些操作的安全组件?

时间:2011-08-23 18:24:06

标签: php html css cakephp

我的add_note操作中有一个表单,我不希望SecurityComponent放置其令牌或检查。我该怎么做?

我尝试了requireAuth('some_other_action')等,但它不起作用。

2 个答案:

答案 0 :(得分:5)

在CakePhp 2.3中执行:

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

答案 1 :(得分:4)

CakePHP 1.2至2.2.x的原始答案:

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

更新了CakePHP 2.3+和3.x的答案(如other answer中所述):

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

此外,还可以解锁特定字段(如the comments中所述)

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