编程语言
首页 > 编程语言> > CakePHP Acl自动检查

CakePHP Acl自动检查

作者:互联网

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

解决方法:

我在带有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.
    }
}

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

标签:php,cakephp,cakephp-2-0,acl,cakephp-2-1
来源: https://codeday.me/bug/20190613/1233593.html