I'm only 3 days into my first zend framework project, so forgive me if the
following is obvious..
I have set up the following module-based zend framework (1.8) app:
application/
-- modules/
---- Bootstrap.php
---- admin/
-------- Bootstrap.php
-------- controllers/
-------- forms/
-------- models/
-------- views/
---- blog/
-------- Bootstrap.php
-------- controllers/
-------- forms/
-------- models/
-------- views/
---- default/
-------- Bootstrap.php
-------- controllers/
-------- forms/
-------- models/
-------- views/
As you can see, there is a "global" Bootstrap.php, as well as a
Bootstrap.php for each module.
My plan was to load an authorization plugin into the admin Bootstrap.php as
follows:
protected function _initAuth()
{
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new My_Plugin_Auth());
return $front;
}
This authorization plugin preDispatch() checks if the user is logged in (via
session) and redirects to the login page if not. This authorization plugin
was meant to be used ONLY for modules which registered the Auth plugin (in
this case, admin).
However, it seems that ALL Bootstraps for ALL modules get called for each
request.
Therefore if I send a request for a completely different module controller
(say default module index - a page that does not require authorization), I'm
sent to the admin module login!
This seems counter-intuitive to me. I was thinking of modules as fairly
self-contained units. Why should the admin module need the blog module's
bootstrap?
I understand that at the Bootstrap stage the front controller request hasn't
yet been set up or dispatched, so it's not possible to determine the
module/controller/action.
But what I don't understand is why all the tutorials I've found suggest
putting plugin hooks into the bootstrap?
It doesn't seem possible to put module-specific plugins into the bootstrap?
So where should I put them?
As an ugly hack, I've put the following into my plugin:
if ($request->getModuleName() != 'admin') { return; }
Should I be doing the authorization check in postDispatch() instead somehow?
Best Regards,
Derek
--
View this message in context:
http://www.nabble.com/Loading-of-global-and-module-bootstraps-with-module-specific-plugin-tp24741578p24741578.html
Sent from the Zend Framework mailing list archive at Nabble.com.