Example #1
0
 /**
  * Pre-dispatch routine
  *
  * This will replace the default pre-dispatch routine and call
  * the action-level pre-dispatch function, if it exists. This
  * gives us more flexibility in controlling the process flow.
  *
  * @return void
  */
 public function preDispatch()
 {
     // Get controller and action names
     $controller = $this->getRequest()->getControllerName();
     $action = $this->getRequest()->getActionName();
     // Automatically add CSS and JS
     $cssFiles = array('default.css', $controller . '.css', $controller . '/' . $action . '.css');
     $cssPrintFiles = array('default.print.css', $controller . '.print.css', $controller . '/' . $action . '.print.css');
     $headLink = $this->view->headLink();
     foreach ($cssFiles as $file) {
         if (!Zend_Loader::isReadable(ZFE_Environment::getFilePath('/css/' . $file))) {
             continue;
         }
         $headLink->appendStylesheet('/css/' . $file, 'screen, print');
     }
     foreach ($cssPrintFiles as $file) {
         if (!Zend_Loader::isReadable(ZFE_Environment::getFilePath('/css/' . $file))) {
             continue;
         }
         $headLink->appendStylesheet('/css/' . $file, 'print');
     }
     $jsFiles = array('default.js', $controller . '.js', $controller . '/' . $action . '.js');
     $headScript = $this->view->headScript();
     foreach ($jsFiles as $file) {
         if (!Zend_Loader::isReadable(ZFE_Environment::getFilePath('/js/' . $file))) {
             continue;
         }
         $headScript->appendFile('/js/' . $file);
     }
     // Call the action's pre-function
     $func = 'pre' . ucfirst(strtolower($action)) . 'Action';
     if (method_exists($this, $func)) {
         $this->{$func}();
     }
 }