I am currently working on a site that requires ACL and as I am using Zend, it makes sense for me to make use of their ACL class but I have little to zero idea of how to do this. I have read the docs but it confused me further...basically all I want to do is to set up two user groups e.g. "normal" and "admin", normal users can access all pages that have a controller that is not admin while admin can obviously access the admin controller pages.
I have many questions:
- How do I set this up?
- Should I run it through a DB or the config.ini?
- Where do I place my ACL.php?
- How do I write such a script?
- How do I then call, is this done in the Index?.
I would very much appreciate if you guide me to a website or a good tutorial.
Play with This structure . get role and resource from database and save this in session for or any caching .
This solution may prove to be the simplest implementation of Zend_Acl.
Example:
Zend/Controller/Action/Helper/Acl.php
I implemented similar thing not so long ago. Basic concept follows in an example code.
I created my own configAcl.php file which is loaded in bootstrap file, in my case it is index.php. Here is how it'd be according to your case:
Another case is if you want to allow normal user only "list" action on all your controllers. It's pretty simple, you'd add line like this:
Next you should create new plugin which takes care of credential checking automatically when there is a request for some controller action. This checking takes place in preDispatch() method that is called before every call to the controller action.
Here is AuthPlugin.php:
Final steps are loading your configAcl.php and register the AuthPlugin in bootstrap file (probably index.php).
So this is the basic concept. I didn't test the code above (copy and paste and rewrite just for the showcase purpose) so it's not bullet-proof. Just to give an idea.
EDIT
For the clarity. The code above in AuthPlugin suppose that the $identity object is filled with user data ("role" column in the database). This could be done within the login process like this: