public function render(Response $res) { $view = $res->data->get('view', $this->config['defaultView']); $layout = $res->data->get('layout', $this->config['defaultLayout']); if ($view) { $viewPathName = $this->config['viewPath'] . '/' . $view . '.php'; if (!file_exists($viewPathName)) { throw new Error('The view file does not exist: ' . $viewPathName); } $view = new View($viewPathName); $res->body = $view->render($res->data->get(), $this->config['viewPath']); } if ($layout) { $res->data['view'] = $res->body; $layoutPathName = $this->config['layoutPath'] . '/' . $layout . '.php'; if (!file_exists($layoutPathName)) { throw new Error('The layout file does not exist: ' . $layoutPathName); } $layout = new View($layoutPathName); $res->body = $layout->render($res->data->get(), $this->config['layoutPath']); } return $res; }