CakePHP Acl自动检查

Cod*_*ant 4 php acl cakephp cakephp-2.0 cakephp-2.1

我是CakePHP框架的新手.我对CakePHP知之甚少.所以我的问题是:ACL是自动运行还是我需要手动检查?

Old*_*ool 5

我在带有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.
    }
}
Run Code Online (Sandbox Code Playgroud)

除了'Pages'控制器之外,所有控制器/操作都经过ACL检查,如果用户没有访问权限,则会提供'pages/forbidden'视图,并且还会将日志条目写入auth.log文件(可选) ,但我当时更喜欢这个).