Пример #1
0
 /**
  * Main function, acts as a dispatcher, reads the controller
  * and actions from the request URI, and calls the correct
  * function, and renders the data.
  *
  * @access private
  * @return void
  **/
 private function run()
 {
     /** Load Config from cache **/
     $cfg = Zend_Registry::get("config");
     if (!$cfg instanceof Zend_Config) {
         throw new Exception("Config not set, check your setup");
     }
     /** Get Controller from URI **/
     $controller = Gecko_Request::getVar("controller");
     $controller = isset($controller) ? $controller : 'index';
     /** Clean up Controller **/
     if (strpos($controller, "/") !== false) {
         $temp = explode("/", $controller);
         $controller = $temp[0];
     }
     if (strpos($controller, ".php") !== false) {
         // weird htaccess error with index controller
         $controller = str_replace(".php", "", $controller);
     }
     /** Get Action from URI **/
     $action = Gecko_Request::getVar("action");
     if (!$action && !empty($temp[1])) {
         $action = $temp[1];
     } elseif (!$action) {
         $action = "index";
     }
     /** Check we have a valid value for controller and action **/
     if (!isset($controller) || !isset($action)) {
         throw new Exception("Controller and Action missing, please check your request URI");
     }
     /** Save values **/
     $this->controllerName = $controller;
     $this->currentAction = $action;
     /** Load Controller **/
     $controller = $this->loadController($controller);
     $this->currentController = $controller;
     /** Create a input request object **/
     $request = new Gecko_Request();
     /** Call Correct Action **/
     $CallAction = $action . "Action";
     /** All actions are called with the original $request parameter see GeckoGPC for more info **/
     if (!is_callable(array($controller, $CallAction))) {
         $controller->noRoute($request);
         /* call noRoute if Action is not callable */
     } else {
         $controller->{$CallAction}($request);
         /** or call action **/
     }
     /** Load View from Controller **/
     $view = $this->loadView($controller->getView());
     $view->setVars($controller->getVars());
     /** Set Correct Layout **/
     if ($controller->isLayoutSet()) {
         $view->setLayout($controller->getLayout());
     }
     /** Set Correct Template **/
     if ($controller->isTemplateSet()) {
         $view->setTemplate($controller->getTemplate());
     } else {
         $view->setTemplate($action);
     }
     /** Save View **/
     $this->view = $view;
     /** Load Config Template Helpers **/
     $helpers = $cfg->TemplateHelpers->toArray();
     if (is_array($helpers)) {
         foreach ($helpers as $helperFile) {
             $view->registerHelper($helperFile);
         }
     } elseif (!empty($helpers)) {
         $view->registerHelper($helpers);
     }
     /** Finally Render data and output to browser or osd **/
     $view->render();
     /** Cleanup and quit application **/
     $controller = null;
     $view = null;
 }
Пример #2
0
 /**
  * Returns a parameter
  *
  * @param string $param The param to get
  * @return mixed The parameter
  */
 public function getParam($param)
 {
     return Gecko_Request::getVar($param);
 }