Пример #1
0
 /**
  *
  */
 public function render(ViewModel $model, Response $response)
 {
     $body = '';
     $engine = $this->getEngine();
     // Create the ROOT node
     $data = $this->dataNode($model->getData(), false);
     // Get the layout name
     $layout_name = $model->getLayout();
     $engine->defAlias('layout', $layout_name);
     // (1) Render the view script
     $view_name = $model->getTemplate();
     if ($view_name) {
         $body = $engine->execute($view_name, $data, null);
         if ($body === false) {
             $error = $engine->getFirstError();
             $this->logSubError($error);
             $info = isset($error['message']) ? '(' . $error['message'] . ')' : '';
             throw new Exception\RuntimeException("View script [{$view_name}] could not be loaded {$info}");
         }
     }
     // Push view errors (DEBUG)
     $data['view_errors'] = $engine->getErrors();
     // (2) Render the layout
     if ($layout_name) {
         $data['content'] = $body;
         $layout = $engine->execute($layout_name, $data, null);
         if ($layout === false) {
             $error = $engine->getFirstError();
             $this->logSubError($error);
             $info = isset($error['message']) ? '(' . $error['message'] . ')' : '';
             throw new Exception\RuntimeException("Layout script [{$layout_name}] could not be loaded {$info}");
         }
         $body = $layout;
     }
     $response->setBody($body);
 }
Пример #2
0
 /**
  * Creates an error model
  * @throws Exception\RuntimeException
  */
 protected function createError(Resources $context, $message, $status = 404)
 {
     $response = $context->getResponse();
     $config = $context->getConfig();
     $layout = $config->value('view.error_layout');
     if (!$layout) {
         throw new Exception\RuntimeException("[ERROR LAYOUT NOT SET] {$message}", 2);
     }
     $debug = $config->value('application.environment') == 'development';
     $error = array('status' => array('code' => $status, 'text' => Message\HttpStatus::message($status)), 'debug' => $debug);
     if ($debug) {
         $error['message'] = $message;
         $error['backtrace'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
     }
     $response->setStatusCode($status);
     $model = new ViewModel();
     $model->setLayout($layout)->setTemplate(false)->setData(['errors' => [$error]]);
     return $model;
 }
Пример #3
0
 /**
  * Generates an error page
  *
  */
 public function errorAction()
 {
     return ViewModel::error(404, "Murlocks ate this page");
 }
Пример #4
0
 /**
  * @param type $model
  * @return string|false|null
  */
 protected function modelLayout(ViewModel $model)
 {
     $layout = $model->getLayout();
     return $layout;
 }