Prev | Current Page 195 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

com>
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
{
$this->_auth = Zend_Auth::getInstance(); |#1
$this->_acl = $options['acl']; |
}
/**
* Hook into action controller initialization
* @return void
*/
public function init() #2
{
$this->_action = $this->getActionController();
// add resource for this controller
$controller = $this->_action->getRequest()->getControllerName();
if(!$this->_acl->has($controller)) {
$this->_acl->add(new Zend_Acl_Resource($controller));
}
}
}
(annotation) <#1. Constructor.>
(annotation) <#2. Initialisation.>
(#1) The constructor is used to pass in an instance of the Acl object that we will use via the options array.
We have to use the options array as the constructor signature is already set in the parent
Zend_Controller_Action_Helper_Abstract class. As the Zend_Auth class is a singleton, we can use its
getInstance() function to collect a reference to it.
(#2) The init() function is called immediately before the call to the controller??™s init() function. This makes
it an ideal place to set up the required resource for the controller: the controller??™s name. We don??™t need any
more resources than that, as we will use Zend_Acl??™s privileges as the actions, so that we don??™t have the
performance hit of working out the names of the action functions dynamically.


Pages:
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
mimre.benton.pl bramy projektowanie stron gdynia stolarka aluminiowa częstochowa serwis drukarek katowice