【问题标题】:CakePHP Acl auto checkingCakePHP Acl 自动检查
【发布时间】:2012-04-16 09:40:04
【问题描述】:

我是 CakePHP 框架的新手。我对 CakePHP 没有足够的了解。所以我的问题是:ACL 是自动工作还是我需要手动检查?

【问题讨论】:

    标签: php cakephp cakephp-2.0 acl cakephp-2.1


    【解决方案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 文件好吧(可选,但我当时更喜欢这个)。

    【讨论】:

      【解决方案2】:

      如果配置正确,AclComponent 会自动检查用户是否有权访问操作。

      来源:我对 CakePHP 1.3 的体验

      【讨论】:

      • 我正在开发 CakePHP 2.1。但它不能自动工作。但是$this->Acl->check() 返回了正确的结果。
      猜你喜欢
      • 2012-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 2013-01-11
      相关资源
      最近更新 更多