I'm wondering much the same thing so would like to repeat the request for some opinions on this.
I've read through the quick start and documentation but I'm having a tough time figuring out where the best place would be to place the verification code (hasIdentity) in the new boot strap framework. For example, in my "Bootstrap extends Zend_Application_Bootstrap_Bootstrap" class I was thinking of adding a protected method "_initAuth". But I'm struggling to figure out if this is the best place to check authorization for is it still having a BaseController:reDispatch method as I had before.
Basically, assuming I am using Zend_Auth and I want to protect my entire application, where now is the best place to put the validation code, and how best to redirect the user back to the login page? Any simple example code would be much appreciated. Thanks!
I'm wondering much the same thing so would like to repeat the request for some opinions on this.
Hi.
This tutorial
http://akrabat.com/wp-content/upload...d-auth_108.pdf
set up the mehod preDispatch in the
indexController
[PHP]
function preDispatch()
{
$auth = Zend_Auth::getInstance();
if (!$auth->hasIdentity()) {
$this->_redirect('auth/login');
}
}
[/PHP]
but I figure out you should set up
it in all your controller![]()
so it'd be far better if you could
set up it in Zend_Application_Bootstrap_Bootstrap.
I tried with _initAuth and it seems to work fine
I'm also new at zf so I form a queue.
Bye.
I would recommend putting your access control into a plugin so that it's decoupled from the rest of your logic, otherwise you are asking for a world of hurt as your application grows and roles are added / changed due to business requirements.
A good starting point is outlined in this tutorial: Zend_Acl / Zend_Auth Example Scenario . The logic outlined here should get you going but you will probably have to change a few things to make it compatible with 1.8.
I'm taking a look at your useful link
and just playing around with it so ....
It's right to set up the plugin
in the bootstrap in this way
[PHP]
protected function _initAcl()
{
$front = Zend_Controller_Front::getInstance();
$plugIn = new Plugin_Acl(new Zend_Acl());
$front->registerPlugin($plugIn);
}
[/PHP]
Last edited by whisher; 05-31-2009 at 11:20 AM.
Just an other starting point
Zend_Acl part 1: Misconceptions and simple ACLs | CodeUtopia