cakephp - 在本地开发环境中禁用 CakePHP ACL/ACO 检查

标签 cakephp

我试图在本地开发环境中禁用 ACL/ACO 检查,因为每次创建新方法或 Controller 时同步 ACO 表非常耗时。我在弄清楚如何有条件地执行此操作时遇到问题。我在 AppController 中尝试了以下代码,但没有成功:

public function beforeFilter() {
    parent::beforeFilter();

    // disable ACL component in local development environments
    if(preg_match('/\.local/',FULL_BASE_URL)){
        unset($this->components['Acl']);
        unset($this->components['Auth']['authorize']);
    }
}

我正在运行 CakePHP 2.x

最佳答案

您可能可以通过这种方式实现相同的目的:

在你的 app/Config/core.php 添加一个配置

Configure::write('Auth.enabled', 0);

与“自动检测”您的环境相比,拥有显式配置通常更受欢迎。

然后,在您的 AppController 中;

public function beforeFilter()
{
    if(0 === Configure::read('Auth.enabled')) {
        $this->Auth->allow();
    }
}

参见 Making actions public

或者,完全禁用组件:

public function beforeFilter()
{
    if(0 === Configure::read('Auth.enabled')) {
        $this->Components->disable('Acl');
        $this->Components->disable('Auth');
    }
}

关于cakephp - 在本地开发环境中禁用 CakePHP ACL/ACO 检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15772645/

相关文章:

linux - 在 Linux 服务器上安装 Cake PHP 网站

php - CakePHP w/jQuery (Javascript/Ajax) 简单链接和更新 - 我做错了什么?

php - CakePHP 和 GROUP BY

php - 在 Linux 上安装 CakePHP 时出现问题

php - 如何在 CakePHP 3 中使用 postGIS

php - CakePHP 迁移数据库行

cakephp - Linux环境下如何烘焙蛋糕 - Cakephp

cakephp - blackhole cakephp 2 关联实体

javascript - 如何在cakephp中调用 View 文件中的函数?

php - 如何配置 CakePHP 的 $this->Auth->login() 以使用自定义密码哈希