Skip to end of metadata
Go to start of metadata

Introduction

This example shows how to implement Zend_Acl with a database backend. Roles, Resources and Users are stored in a database and can easily be queried. This ACL implementation uses 5 basic roles and uses Zend_Acl inheritance.

Firstly, the database tables and initial roles and resources need to be built.

Ini files

I have chosen to use .ini files for the initial setup for ease of use and customization.

roles.ini

This .ini defines the roles to be used in the ACL.

roles.ini

users.ini

This .ini file simply maps users to roles for the initial build.

users.ini

resources.ini

This .ini file maps resources to roles for the initial build. The resources will be stored in the database as 'group:resource'. In the example .ini file below this would mean that the 'Load' resource would be stored as 'Applications:Load'.

resources.ini

Database Initialisation:

The following code uses the above .ini files to build the initial database tables.

BuildRoles.php

BuildRoles.php

BuildUsers.php

BuildUsers.php

BuildResources.php

BuildResources.php

Main ACL class:

Example Usage

ExampleController.php

Testing

TestController.php

/view/scripts/test/acl.phtml

Example output from - http://localhost/MyApp/test/acl?user=dino

Example from - http://localhost/MyApp/test/acl?user=

Labels:
acl acl Delete
zend_acl zend_acl Delete
database database Delete
example example Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.