【发布时间】:2012-04-16 09:40:04
【问题描述】:
我是 CakePHP 框架的新手。我对 CakePHP 没有足够的了解。所以我的问题是:ACL 是自动工作还是我需要手动检查?
【问题讨论】:
标签: php cakephp cakephp-2.0 acl cakephp-2.1
我是 CakePHP 框架的新手。我对 CakePHP 没有足够的了解。所以我的问题是:ACL 是自动工作还是我需要手动检查?
【问题讨论】:
标签: php cakephp cakephp-2.0 acl 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.
}
}
除了“页面”控制器之外,所有控制器/操作都经过 ACL 检查,如果用户无权访问,则会提供“页面/禁止”视图,并将日志条目写入 auth.log 文件好吧(可选,但我当时更喜欢这个)。
【讨论】:
如果配置正确,AclComponent 会自动检查用户是否有权访问操作。
来源:我对 CakePHP 1.3 的体验
【讨论】:
$this->Acl->check() 返回了正确的结果。