Beispiel #1
0
 /**
  * Select the ViewRenderer
  * 
  * @param  ViewEvent $e
  * @return ViewRenderer
  */
 public function selectRenderer(ViewEvent $e)
 {
     if ($this->enhanced == false) {
         $request = $e->getRequest();
         $model = $e->getModel();
         // this happens if the route is not matched properly
         if (!$request instanceof Request) {
             $request = new Request();
             $e->setRequest($request);
         }
         // add base elements
         $model->setVariable("base_url", $request->getServerUrl() . $request->getBaseUrl());
         $model->setVariable("request", $request);
         $model->setVariable("config", Registry::getInstance());
         // add navigation
         $nav = new Navigation($e);
         $model->setVariable("navbar", $nav->getNavbar());
         // show internal xml
         if ($request->getParam('format') == 'xerxes') {
             $this->renderer->setFormat('xml');
         } else {
             // determine which view script to use
             if ($e->getResponse()->getStatusCode() != 200) {
                 $model->setVariable("display_exceptions", true);
                 $model->setTemplate('error/index.phtml');
             } else {
                 // determine which view script to use
                 $script = $request->getControllerMap()->getView($request->getParam('format'));
                 // test view chosen
                 // header("Content-type: text/xml"); echo $request->getControllerMap()->saveXML();	echo "<!-- $script -->"; exit;
                 $model->setTemplate($script);
             }
             // render it
             $display_as = "html";
             if ($request->getParam('format') == 'json') {
                 $display_as = "json";
             }
             $this->renderer->setFormat($display_as);
         }
         $this->enhanced = true;
     }
     return $this->renderer;
 }
Beispiel #2
0
 /**
  * Select the ViewRenderer
  * 
  * @param  ViewEvent $e
  * @return ViewRenderer
  */
 public function selectRenderer(ViewEvent $e)
 {
     if ($this->enhanced == false) {
         $request = $e->getRequest();
         $model = $e->getModel();
         $registry = Registry::getInstance();
         // this happens if the route is not matched properly
         if (!$request instanceof Request) {
             $request = new Request();
             $e->setRequest($request);
         }
         // add base elements
         $model->setVariable("base_url", $request->getServerUrl() . $request->getBaseUrl());
         $model->setVariable("request", $request);
         $model->setVariable("config", $registry);
         // add navigation
         $nav = new Navigation($e);
         $model->setVariable("navbar", $nav->getNavbar());
         ### flatten model
         // @todo this seems really hacky, but our view renderer
         // has no notion of children, so this makes our lives easier
         foreach ($model->getChildren() as $child) {
             // template specified
             $model->setTemplate($child->getTemplate());
             // terminate this?
             $model->setTerminal($child->terminate());
             // options
             $options = $child->getOptions();
             foreach ($options as $id => $value) {
                 $model->setOption($id, $value);
             }
             // variables
             $child_variables = $child->getVariables();
             foreach ($child_variables as $id => $value) {
                 $model->setVariable($id, $value);
             }
         }
         // show internal xml
         if ($request->getParam('format') == 'xerxes') {
             $this->renderer->setFormat('xml');
         } else {
             // error
             if ($e->getResponse()->getStatusCode() != 200) {
                 $display_excpetions = false;
                 if ($_SERVER['APPLICATION_ENV'] == 'development' || $registry->getConfig('DISPLAY_ERRORS', false, false) == true) {
                     $display_excpetions = true;
                 }
                 $model->setVariable("display_exceptions", $display_excpetions);
                 if ($e->getResponse()->getStatusCode() == 404) {
                     $model->setTemplate('error/404.phtml');
                 } else {
                     $model->setTemplate('error/index.phtml');
                 }
             } elseif (!strstr($model->getTemplate(), '.')) {
                 $script = $request->getControllerMap()->getView($request->getParam('format'));
                 // test view chosen
                 // header("Content-type: text/xml"); echo $request->getControllerMap()->saveXML();	echo "<!-- $script -->"; exit;
                 $model->setTemplate($script);
             }
             // render it
             $display_as = "html";
             if ($request->getParam('format') == 'json') {
                 $display_as = "json";
             }
             $this->renderer->setFormat($display_as);
         }
         $this->enhanced = true;
     }
     return $this->renderer;
 }
 /**
  * Add the navigation menu to the response
  */
 public function menuAction()
 {
     $nav = new Navigation($this->event);
     $this->response->setVariable("navbar", $nav->getNavbar());
 }