Hi.

In my Zend_Controller_Plugin_Abstract::routeStartup() I'm pushing
custom actions to the actionstack. The problem is that
$this->getFrontController()->getRequest()->get[Action|Module]Name()
inside my Zend_Controller_Action::postDispatch() return the same
module/action as "in the URL", but in the controller plugin I'm
calling $actionstack->actionToStack('navpane','index',$module);

Do you have any idea what could cause this?



Here are some relevant pieces of code:

class My_Plugin_Initialize extends Zend_Controller_Plugin_Abstract {
        //....
public function routeStartup(Zend_Controller_Request_Abstract $request) {
        //....
                $this->initView()
                        ->initLayout()
                        ->initModules()
                        ;
        }
public function initModules() {
                $this->logger->info(__METHOD__);
                $this->front->addModuleDirectory($this->config->modulesPath);
                
                $actionstack =
Zend_Controller_Action_HelperBroker::getStaticHelper('ActionStack');
                        
                $modules = $this->config->module->toArray();
                $this->logger->table($modules,'modules');
                
                foreach($modules as $module => $settings) {
                        if($settings['active'] && $settings['navbar']) {
                                $this->logger->info('module navpane: ' . 
$module);
                                
$actionstack->actionToStack('navpane','index',$module
                                , array('module' => $module, 'controller' => 
'index','action' => 'navpane')
                                 /*,$this->getRequest()->getParams()*/);
                        }
                }
                /**
                 * It can be done here, or in 
My_Controller_Action::preDispatch()
                 * If done here, it is impossible not to have the default 
action triggered.
                 * If done there, you can ensure you get an 
/default/index/index only if a
                 * My_Controller_Action is instanced, which should provide a 
greater
                 * flexibility later, That's why it's commented out.
                 */
                //$actionstack->actionToStack('index','index','default');
                return $this;
        }
}

//-----------------------
<?php
require_once 'Zend/Controller/Action.php';

/*
 * @todo $_has* variables should be members of the view
 *
 * This class does not take care of actually creating your widgets, it only
 * generates the necessary js code to attach to "onload". You still need to
 * create your tab or navbar panels in your action.phtml,
 * with the IDs following the namescheme '{$module}_tab_{$action}' or
'default_ui_{$module}-pane'
 * or both.
 */
class My_Controller_Action extends Zend_Controller_Action {
        private $_hasTab = FALSE;
        private $_hasSidebar = FALSE;
        private $_activateSidebar = FALSE; //TODO: if $_hasSidebar and
$_activeSidebar, then activate in postDispatch()
        private $_activateTab = FALSE;

        protected static $_predispatched = 0;//lock var, we need to append the 
default
        private $_directCall = TRUE;//call module/controller/action only if
it has not already been done automatically
        //...
        public function preDispatch() {
                $logger = Zend_Registry::get('logger');
                $logger->info(get_class($this).'->'.__FUNCTION__);
                if(!My_Controller_Action::$_predispatched) {
                        $fc = $this->getFrontController();
                        $default = implode('/',array(
                                $fc->getDefaultModule(),
                                $fc->getDefaultControllerName(),
                                $fc->getDefaultAction()
                                )
                        );
                        $wanted = $this->_request->getParams();
                        $wanted = 
implode('/',array($wanted['module'],$wanted['controller'],$wanted['action']));
                        
                        if($default !== $wanted) {//called directly, eg 
/forum/index/index
                                $actionstack =
Zend_Controller_Action_HelperBroker::getStaticHelper('ActionStack');
                                
$actionstack->actionToStack('index','index','default');
                        }
                        else {
                                $this->_directCall = FALSE;
                        }
                        My_Controller_Action::$_predispatched++;
                }
        }
        
        public function postDispatch() {
                $fc = $this->getFrontController();
                
                $logger = Zend_Registry::get('logger');
                $logger->info(get_class($this).'->'.__FUNCTION__);
                
                if($this->_hasTab || $this->_hasSidebar) {
                        $action = $fc->getRequest()->getActionName();
                        $module = $fc->getRequest()->getModuleName();
                        
                        $activateTab = '';
                        $insertTab = '';
                        if($this->_hasTab) {
                                $insertTab = 'var tabContainer = 
dijit.byId("default_ui_mainTabs");
                                        var nt = 
dijit.byId("'.$module.'_tab_'.$action.'");
                                        tabContainer.addChild(nt);
                                        ';
                                if($this->_activateTab) {
                                        $activateTab = 
'tabContainer.selectChild(nt);
                                        ';
                                }
                        }
                        
                        $activateSidebar = '';
                        $insertSidebar = '';
                        $logger->info("hasSidebar: 
".print_r($this->_hasSidebar,TRUE));
                        if($this->_hasSidebar) {
                                $logger->info("inserting sidebar for $module");
                                $insertSidebar = 'var sidebarContainer = 
dijit.byId("default_ui_navPane");
                                        var nt = 
dijit.byId("default_ui_'.$module.'-pane");
                                        sidebarContainer.addChild(nt);
                                        ';
                                if($this->_activateSidebar) {
                                        $activateSidebar = 
'sidebarContainer.selectChild(nt);
                                        ';
                                }
                        }
                        
                        $this->view->dojo()->onLoadCaptureStart();
                        
                        $out = 'function() {//for 
/'.implode('/',$this->getRequest()->getParams()).'
                                        '.$insertTab.$activateTab.
                                        $insertSidebar.$activateSidebar.'
}';
                        echo $out;
                        $this->view->dojo()->onLoadCaptureEnd();
                }
        }

--Flavius

Reply via email to