/** * Handle an incoming web request. */ public function handleRequest() { try { $this->response = parent::handleRequest(); } catch (HttpException $ex) { $this->config->set('page_title', 'Error'); $view = new View('exception'); $view->exception = $ex; $this->response->setResponseCode($ex->getErrorCode()); $this->response->setContent($view->render()); } catch (\Exception $ex) { $this->config->set('page_title', 'Error'); $view = new View('exception'); $view->exception = $ex; $this->response->setResponseCode(500); $this->response->setContent($view->render()); } if (View::exists('layout') && $this->response->hasLayout()) { $view = new View('layout'); $pageTitle = $this->config->get('page_title', null); if (!is_null($pageTitle)) { $view->title = $pageTitle; } $view->content = $this->response->getContent(); $this->response->setContent($view->render()); } return $this->response; }
/** * Set the view that this controller action should use. * @param $action */ protected function setView($action) { if (View::exists($this->className . '/' . $action)) { $this->view = new View($this->className . '/' . $action); } }