1

I need to know how to get the current module name in the bootstrap file of my zend application. On the load of the page I'm doing a request to a webservice to get the current user information by sending a hashed cookie and a token. The problem is that I only need to do this in two of my 3 modules so i need to be able to ask for example.

if ($moduleName !== "filteredmodule"){ // do the request }

Thanks.

2 Answers 2

5

Bootstrap is for getting the application ready. I suggest you do this kind of call in a Controller Plugin (which you can use to get the current called module) or in the init() function of your controller.

This is how to get the current module via controller plugin:

<?php

final class YourApp_Controller_Plugin_YourPluginName extends Zend_Controller_Plugin_Abstract {

    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        $module = $request->getModuleName(); //This is the module

Docs: http://framework.zend.com/manual/en/zend.controller.plugins.html

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks i know about this my problem is that I'm doing this $view->navigation() ->setAcl($this->_acl) ->setRole(Zend_Registry::get('role')); in the bootrstrap file and I need that the other code is executed before this because i set the role in there, and controller plugins execute after bootstrap resources. So may be what i should do is move the navigation to a plugin too??
You could keep it like you have it and redefine the navigation ACL Role in the plugin depending on your logic in your plugin
Ashley is right, setting your ACL roles in your Bootstrap may be a bit premature, because routing hasn't even happened yet, so you don't know what resources are being requested (which most likely makes it hard to do your ACL logic).
Ok guys i made it work, i redefined the navigation acl in the plugin, and made a plugin for this webservice request, thank you very much guys
0

One thing regarding Ashley's answer:

If you want to do

$module = $request->getModuleName();

as soon as possible, then do it in routeShutdown().

As the documentation states, "routeStartup() is called before Zend_Controller_Front calls on the router to evaluate the request against the registered routes. routeShutdown() is called after the router finishes routing the request."

So router dependant request parameters like module, controller, action or any other parameters specified in the route will be accessible in routeShutdown() and later functions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.