Added by Robert Castley, last edited by Robert Castley on May 15, 2008  (view change)

Labels

 

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.

users.ini

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

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'.

Database Initialisation:

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

BuildRoles.php

BuildUsers.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=