One of the more frustrating things about using Zend Framework is that for pretty much any topic, there is always at least 2 ways to accomplish a particular task. For a beginner with the framework, this is a humungous barrier to overcome. When I try to implement something, my first question is no longer “how will I do this” but “where the hell should I put this code?”. In my case, the problem I was attempting to solve was “how do I implement ACL for one module in my application?”.
I’m using:
Zend Framework 1.10.5
…and Zend_Application
…and building functionality out using modules
So off I go duck hunting and find lots of samples on how to do it. Except none of them fit how my application is currently built. Plugins? Front controllers? Placing code in preDispatch? Yikes, this will take some time to sift through all the available info and come up with a solution custom-tailored to my application’s structure.
I ended up using info from here and here to form my solution. The first step was to create a plugin to hold all the info about my ACL’s and roles.
Then, I needed a way to actually call this plugin and do something with the results. I was using a base controller for the ‘football’ module for my application, and after messing around, I figured out that the code interacting with my ACL plugin needed to go in the init() method of the controller: