/** * 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; } } }
public function __construct() { $dispatcher = Primitus::registry('Dispatcher'); if ($dispatcher->getPrimaryController() == get_class($this)) { throw new Primitus_Controller_Exception("Cannot access private controller from public space"); } }
/** * 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; } } }
/** * The Primitus View plugin is a procedural function which implements the logic of * the template-level {render} function. It is responsible for either calling the * requested controller's render() method to get the template, or simply processing * the template in the views/ directory if the controller didn't exist. * * You can set template-level variables in the module being rendered by simply setting * them in the smarty {render} function. i.e. * * {render module="blog" action="view" entry=$entry} * * will expose the {$entry} template variable to the blog::view template in /blog/view.tpl * * @category Primitus * @package Primitus * @subpackage View * @copyright Copyright (c) 2006 John Coggeshall * @license http://framework.zend.com/license/new-bsd New BSD License */ function Primitus_View_Plugin_Render($params, &$smarty) { if (!isset($params['module'])) { throw new Primitus_View_Exception("No module name was provided to render"); } $module = $params['module']; if (strtolower(substr($module, strlen($module) - 10)) != "controller") { $module .= "Controller"; } $action = isset($params['action']) ? $params['action'] : "indexAction"; $dispatcher = Primitus::registry('Dispatcher'); $controllerFile = $dispatcher->formatControllerFile($module); if (file_exists($controllerFile)) { // Load the Class Zend::loadClass($module, $dispatcher->getControllerDirectory()); $controller = new $module(); if ($controller instanceof Primitus_Controller_Action_Base) { unset($params['module']); unset($params['action']); if (!empty($params)) { $view = Primitus_View::getInstance($module); foreach ($params as $key => $value) { $view->assign($key, $value); } } return $controller->render($action); } else { throw new Primitus_View_Exception("Bad Request"); } } else { $view = Primitus_View::getInstance($module); unset($params['module']); unset($params['action']); if (!empty($params)) { $view = Primitus_View::getInstance($module); foreach ($params as $key => $value) { $view->assign($key, $value); } } return $view->render($action); } }
<?php /** * Primitus * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * * @category Zend * @package Application * @copyright Copyright (c) 2006 John Coggeshall * @license http://framework.zend.com/license/new-bsd New BSD License */ require_once 'Primitus/Controller/Front.php'; require_once 'Primitus.php'; /** * Enabling Primitus_DEBUG will automatically record and display internal Primitus * routing and dispatcher data on the bottom of every page */ define("PRIMITUS_DEBUG", false); $frontController = Primitus::initializeRequest(); $frontController->dispatch();