public function error($code, $message, $description = null, $no_template = false, $trace = []) { $types = $this->getRequest()->getHeader('accept'); if (!is_array($types)) { $types = [$types]; } if (in_array('application/json', $types)) { $out = array('status' => 'error', 'message' => $message); if ($this->_config->dev_mode) { $out['description'] = $description; } return $this->sendResponse($code, json_encode($out)); } $template = new Template(); $template->setParent($this->_layout); $path = "{$this->_config->templates}/error_{$code}.php"; if (!$template->setPath($path)) { $path = "{$this->_config->templates}/error.php"; } if ($no_template || !$template->setPath($path)) { $this->getResponse()->setContent("<title>Error {$code}: {$message}</title><h1>Error {$code}</h1><p>{$message}</p><p>{$description}</p>"); return $this->sendResponse($code); } $template->set('code', $code); $template->set('message', $message); $template->set('description', $description); if ($this->_config->dev_mode) { $template->set('backtrace', $trace); } $this->_layout->set('error', true); $this->_layout->set('title', "Error {$message}"); $this->_layout->set('content', $template->render()); $content = $this->_layout->render(); return $this->sendResponse($code, $this->_layout->render()); }