Problem with ACL inheriting (Gentoo, PHP-FPM 5.4)
Phalcon\Acl\Exception: Role 'Guests' does not exist in the role list File=/home/site/stage/_config.php Line=46 #0 [internal function]: Phalcon\Acl\Adapter\Memory->addInherit('Administrators', Object(Phalcon\Acl\Role)) #1 /home/site/stage/_config.php(46): Phalcon\Acl\Adapter\Memory->addRole(Object(Phalcon\Acl\Role), Object(Phalcon\Acl\Role)) #2 /home/site/stage/_loader.php(63): require_once('/home/site/stag...') #3 /home/site/stage/index.php(9): require_once('/home/site/stag...') #4 {main}
$acl = new Phalcon\Acl\Adapter\Memory();
// disallow all resources by default
$acl->setDefaultAction(Phalcon\Acl::DENY);
try {
// Create some roles
$roleAdmins = new \Phalcon\Acl\Role("Administrators", "Super-User role");
$roleGuests = new \Phalcon\Acl\Role("Guests");
// Add "Guests" role to acl
$acl->addRole($roleGuests);
// Add "Administrators" role inheriting from "Guests" its accesses
$acl->addRole($roleAdmins, $roleGuests);
} catch (\Phalcon\Exception $e) {
echo get_class($e), ": ", $e->getMessage(), "\n";
echo " File=", $e->getFile(), "\n";
echo " Line=", $e->getLine(), "\n";
echo $e->getTraceAsString();
}
This line must be:
$acl->addRole($roleAdmins, "Guests");
The object-syntax is now supported in 1.0.0
Ok, but how I can do inheriting from multiple roles? It did not work properly in 0.9.1
You could call:
$acl->addRole($roleAdmins, "Guests1");
$acl->addRole($roleAdmins, "Guests2");
I tried on latest versions 1.0, roles-inheriting does not work:
setDefaultAction(Phalcon\Acl::DENY); try { // Create some roles $roleAdmins = new \Phalcon\Acl\Role("Administrators", "Super-User role"); $roleManager = new \Phalcon\Acl\Role("Manager"); $roleGuests = new \Phalcon\Acl\Role("Guests"); ``` $acl->addRole($roleGuests); $acl->addRole($roleManager); // Add "Administrators" role inheriting from "Guests" its accesses $acl->addRole($roleManager, "Guests"); $acl->addRole($roleAdmins, "Manager"); $acl->addResource(new Phalcon\Acl\Resource('main'), ['view', 'moderator']); // allow resource for Guests $acl->allow("Guests", 'main', 'view'); echo " Guests: " . $acl->isAllowed("Guests", 'main', 'view'); echo " Manager: " . $acl->isAllowed("Manager", 'main', 'view'); echo " Administrators: " . $acl->isAllowed("Administrators", 'main', 'view'); ``` } catch (\Phalcon\Exception $e) { echo get_class($e), ": ", $e->getMessage(), "\n"; echo " File=", $e->getFile(), "\n"; echo " Line=", $e->getLine(), "\n"; echo $e->getTraceAsString(); } ... Guests: 1 Manager: 0 Administrators: 0
The same problem. Check forum discussion please: http://forum.phalconphp.com/discussion/103/acl-roles-inheritance
Is any news about this bug?
This is fixed in the 1.0.0 branch