phalcon Working with ACL Creating an ACL


Example

You can create ACL by using Phalcon\Acl\Adapter\Memory class:

$acl = new Phalcon\Acl\Adapter\Memory();

By default phalcon allows action to resource which has not been defined, to change this you can use:

$acl->setDefaultAction(Phalcon\Acl::DENY);

Roles can be added in two ways - using Phalcon\Acl\Role or just plain string:

$roleAdministrator = new Phalcon\Acl\Role('Administrator');
$acl->addRole($roleAdministrator);
$acl->addRole('Customer');

Resources can be added in two ways too, you can add actions as single action or as array:

$resourceCategories = new Phalcon\Acl\Resource('categories');
$acl->addResource($resourceCategories, 'create');
$acl->addResource('products', ['create', 'update']);