我试图在本地开发环境中禁用 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();
}
}
或者,完全禁用组件:
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/