We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



6.9k
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