Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Incubator Acl error

Hello,

I'm using the Incubator Acl and after setting it up as in docs, in Bootstrap, I'm getting this error

Parameter 'name' must be a string

$acl->isAllowed('Guests', $controller, $action) is returning 1;

$session->get('auth') is returning null;

And this is how I register the code:

$acl = new \Phalcon\Acl\Adapter\Database(array(
        'db' => $db,
        'roles' => 'roles',
        'rolesInherits' => 'roles_inherits',
        'resources' => 'resources',
        'resourcesAccesses' => 'resources_accesses',
        'accessList' => 'access_list',
    ));

$di->set($acl, 'acl');

I'm doing something wrong, or I need to do something more? It is a multi module application.

Thank you



5.8k
Accepted
answer
$di->set($acl, 'acl');

You've got the arguments the wrong way around, name should come first.

eg.

$di->set('acl', $acl);

//OR a more efficient approach

$di->set('acl', function() use ($db){
    return new \Phalcon\Acl\Adapter\Database(array(
        'db' => $db,
        'roles' => 'roles',
        'rolesInherits' => 'roles_inherits',
        'resources' => 'resources',
        'resourcesAccesses' => 'resources_accesses',
        'accessList' => 'access_list',
    ));
});

haha.. funny how I didn't notice what stupid thing I wrote. Thank you