protected function response($data = array(), $http_code = 200) { if (empty($data)) { \Output::$status = 404; return; } \Output::$status = $http_code; // If the format method exists, call and return the output in that format if (method_exists('Controller_Rest', '_format_'.$this->request->format)) { // Set the correct format header \Output::set_header('Content-Type', $this->_supported_formats[$this->request->format]); $this->output = $this->{'_format_'.$this->request->format}($data); } // Format not supported, output directly else { $this->output = (string) $data; } }
public function action_404() { $messages = array('Aw, crap!', 'Bloody Hell!', 'Uh Oh!', 'Nope, not here.', 'Huh?'); $data['title'] = $messages[array_rand($messages)]; // Set a HTTP 404 output header Output::$status = 404; $this->render('welcome/404', $data); }
/** * Shows a 404. Checks to see if a 404_override route is set, if not show * a default 404. * * Usage: * * <code>Request::show_404();</code> * * @access public * @return void */ public static function show_404($return = false) { logger(Fuel::L_INFO, 'Called', __METHOD__); \Output::$status = 404; if (\Config::get('routes.404') === null) { static::active()->output = \View::factory('404'); } else { list($controller, $action) = array_pad(explode('/', \Config::get('routes.404')), 2, false); $action or $action = 'index'; $class = '\\Controller_' . ucfirst($controller); $method = 'action_' . $action; if (class_exists($class)) { $controller = new $class(static::active()); if (method_exists($controller, $method)) { // Call the before method if it exists if (method_exists($controller, 'before')) { $controller->before(); } $controller->{$method}(); // Call the after method if it exists if (method_exists($controller, 'after')) { $controller->after(); } // Get the controller's output if ($return) { return $controller->output; } exit($controller->output); } else { throw new \Exception('404 Action not found.'); } } else { throw new \Exception('404 Controller not found.'); } } }
public function action_404() { // Set a HTTP 404 output header Output::$status = 404; $this->render('welcome/404'); }