예제 #1
0
 public function toString() : string
 {
     $content = "Content-Type: text/html; charset=utf-8" . Email::EOL;
     $view = new View();
     $content .= $view->render($this->_viewFile, $this->_viewTemplate, $this->_viewData);
     return $content;
 }
예제 #2
0
 public function index(Request $request) : Response
 {
     $response = new Response();
     $response->contentType("html");
     $view = new View();
     $response->body($view->render("Page/App/index", "Layout/App/template", ['title' => 'Home']));
     return $response;
 }
예제 #3
0
 /**
  * Used to render the message set in FlashMiddleware::set()
  *
  * In your view: $this->Flash->render('somekey');
  * Will default to flash if no param is passed
  *
  *
  * @param array|string $names The Flash messages you are rendering in the view.
  * @return string|void Rendered flash messages or null if flash stack does not exist
  *   in session.
  * @throws \UnexpectedValueException If value for flash settings key is not an array.
  */
 public function render($names = [])
 {
     $messages = $this->flashMessages($names);
     $view = new View();
     $out = '';
     foreach ($messages as $message) {
         $out .= $view->render($message['fragment'], $message['params']);
     }
     return $out;
 }
예제 #4
0
 /**
  * Render the cell.
  *
  * @return string The rendered cell.
  * @throws MissingCellViewException When a MissingTemplateException is raised during rendering.
  */
 public function render() : string
 {
     $view = new View();
     $className = substr(strrchr(get_class($this), "\\"), 1);
     $name = substr($className, 0, -4);
     $viewFile = 'Cell' . DIRECTORY_SEPARATOR . $name;
     $view->loadHelpers($this->helpers);
     try {
         return $view->render($viewFile, $this->_viewVars);
     } catch (MissingTemplateException $e) {
         throw new MissingCellViewException(['file' => $viewFile, 'name' => $name]);
     }
 }
예제 #5
0
 public function processError($request, $exception)
 {
     $response = new Response();
     $viewVars = ["exception" => $exception];
     $code = 500;
     $errorCode = $exception->getCode();
     if ($errorCode >= 400 && $errorCode < 506) {
         $code = $errorCode;
     }
     $response->statusCode($code);
     $viewVars["code"] = $code;
     if (method_exists($exception, 'responseHeader')) {
         $response->header($exception->responseHeader());
     }
     if ($request) {
         $viewVars["url"] = $request->url();
     }
     $isDebug = Configuration::getInstance()->get("debug");
     if ($isDebug) {
         $viewVars['trace'] = Debugger::formatTrace($exception->getTrace(), ['format' => 'array', 'args' => false]);
     }
     $message = $exception->getMessage();
     $isHttpException = $exception instanceof HttpException;
     if (!$isDebug && !$isHttpException) {
         if ($code < 500) {
             $message = \CoreTyson\tr('cake', 'Not Found');
         } else {
             $message = \CoreTyson\tr('cake', 'An Internal Error Has Occurred.');
         }
     }
     $viewVars["message"] = $message;
     $template = "error" . $code;
     if (!$isDebug && !$isHttpException) {
         $template = 'error500';
         if ($code < 500) {
             $template = 'error400';
         }
     }
     if ($isHttpException) {
         $template = 'error500';
         if ($code < 500) {
             $template = 'error400';
         }
     }
     if ($exception instanceof PDOException) {
         $template = 'pdo_error';
     }
     try {
         $view = new View();
         $response->body($view->render("Error/" . $template));
     } catch (MissingTemplateException $e) {
         return $this->_outputMessageSafe('error500');
     } catch (MissingPluginException $e) {
         $attributes = $e->getAttributes();
         if (isset($attributes['plugin']) && $attributes['plugin'] === $this->controller->plugin) {
             $this->controller->plugin = null;
         }
         return $this->_outputMessageSafe('error500');
     } catch (Exception $e) {
         return $this->_outputMessageSafe('error500');
     }
 }