简体   繁体   English

CakePHP Acl自动检查

[英]CakePHP Acl auto checking

I am novice to the CakePHP framework. 我是CakePHP框架的新手。 I don't have enough knowledge about CakePHP. 我对CakePHP知之甚少。 So my question is: Does ACL works automatically or do I need to check it manually? 所以我的问题是:ACL是自动运行还是我需要手动检查?

I have this in the AppController of my latest CakePHP 1.3 project with ACL, should be fairly similar in CakePHP 2.1. 我在带有ACL的最新CakePHP 1.3项目的AppController中有这个,在CakePHP 2.1中应该非常相似。

function beforeFilter() {
    // ACL Check
    if($this->name != 'Pages' && !$this->Acl->check(array('model' => 'User', 'foreign_key' => $this->Session->read('Auth.User.id')), $this->name . '/' . $this->params['action'])) {
        CakeLog::write('auth', 'ACL DENY: ' . $this->Session->read('Auth.User.name') . ' tried to access ' . $this->name . '/' . $this->params['action'] . '.');
        $this->render('/pages/forbidden');
        exit; // Make sure we halt here, otherwise the forbidden message is just shown above the content.
    }
}

Apart from the 'Pages' controller, all controllers/actions are ACL-checked and if a user has no access, the 'pages/forbidden' view is served instead and a log entry is written to the auth.log file as well (optional, but I preferred this at the time). 除了“页面”控制器之外,所有控制器/操作都经过ACL检查,如果用户没有访问权限,则会提供“pages / forbidden”视图,并且还会将日志条目写入auth.log文件(可选) ,但我当时更喜欢这个)。

If you've configured it correctly, the AclComponent automagically checks if a user has access to an action. 如果您已正确配置它,AclComponent会自动检查用户是否有权访问某个操作。

Source: My experience with CakePHP 1.3 资料来源:我对CakePHP 1.3的体验

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM