如何允许使用安全组件进行操作?

时间:2013-08-28 18:10:46

标签: security cakephp authentication

我收到此错误

Call to undefined method SecurityComponent::allowedActions()    

当我尝试在这样的控制器中允许单击动作时

public function beforeFilter() {
            parent::beforeFilter();
            $this->Security->allowedActions(array('sign-up'));
            $this->Auth->allow('login','signup','index','activate','logout','forgot','reset','display');
            if($this->Auth->user('id')) {
                $this->set('logged_in', true);
            } else {
                $this->set('logged_in', false);
            }
        }

        public $components = array('RequestHandler');

如果我删除

$this->Security->allowedActions(array('sign-up'));

当我提交注册表单时,它显示您的请求已被黑色

1 个答案:

答案 0 :(得分:2)

没有这样的方法,allowedActionsSecurityComponent属性

http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#SecurityComponent::$allowedActions

$this->Security->allowedActions = array('sign-up');

此外,您在signup中使用AuthComponent::allow(),因此请确保sign-up确实是该操作的正确名称(我真的怀疑这是因为这将是无效的PHP语法)。< / p>