2
votes

I am attempting to disable ACL/ACO checks in my local development environment because its time consuming to sync up the ACO table everytime I create a new method or controller. I am having problems figuring out how to do this conditionally. I attempted the following code in AppController but it did not work:

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']);
    }
}

I am running CakePHP 2.x

1

1 Answers

6
votes

You can probably achieve the same this way:

Add a configuration in your app/Config/core.php

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

Having an explicit configuration is generally preferred over 'auto-detecting' your environment.

Then, inside your AppController;

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

See Making actions public

Or, to disable the component(s) altogether:

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