/** * Render the primary template, setting the variables for the first action and * redirects the user to the noroute template if necessary */ public static function render() { $engine = new Primitus_View_Engine(); $dispatcher = Primitus::registry('Dispatcher'); $action = $dispatcher->getFirstAction(); $moduleName = $dispatcher->formatControllerName($action->getControllerName()); $actionName = $dispatcher->formatActionName($action->getActionName()); $controller = new $moduleName(); $content_type = $controller->getContentType($action); header("Content-type: {$content_type}"); if ($moduleName == "IndexController" && $actionName == "norouteAction") { $view = Primitus_View::getInstance($moduleName); print $view->render($action->getActionName()); } else { switch (true) { case $controller instanceof ApplicationController: $engine->assign("__Primitus_Primary_Module_Name", $moduleName); $engine->assign("__Primitus_Primary_Module_Action", $actionName); $engine->display(self::MAIN_TEMPLATE); break; default: $view = Primitus_View::getInstance($moduleName); print $view->render($action->getActionName()); break; } } }
/** * Renders a particular action for this scope, assigning local * view variables and global view variables. * * @param string $action The unqualified action name (i.e. 'noroute') to render * @return string The rendered action from the template processing */ public function render($action) { $templateFile = $this->getTemplatePathByAction($action); if (!$templateFile || !file_exists($templateFile)) { throw new Primitus_View_Exception("Could not find expected template '{$templateFile}"); } $engine = new Primitus_View_Engine(); foreach (self::$_global_tpl_vars as $key => $value) { $engine->assign($key, $value); } foreach ($this->_local_tpl_vars as $key => $value) { $engine->assign($key, $value); } return $engine->fetch($templateFile); }
/** * Dispatch the request to the dispatcher, catching any errors which bubble up * to the surface and, in that event, display a nice template describing the error * with debugging information. This method also controls the displaying of debug * information in every request. */ public function dispatch() { try { Primitus::startTimer('request'); parent::dispatch(); $request_time = number_format(Primitus::stopTimer('request'), 2); if (defined("Primitus_DEBUG") && Primitus_DEBUG) { $engine = new Primitus_View_Engine(); $debugInfo = Primitus::generateDebuggingData(); $engine->assign("debug", $debugInfo); $engine->display("_main/debug.tpl"); } } catch (Exception $e) { $originalError = $e; try { $engine = new Primitus_View_Engine(); $engine->assign('error', $originalError); $engine->display("_main/error.tpl"); } catch (Exception $e) { $msg = "{$originalError->getMessage()} (Additionally, there was an error in the error handler: {$e->getMessage()})"; print $e->getTraceAsString(); $this->_printUglyMessage($msg); die; } } }