{"id":1598,"date":"2022-08-30T15:17:52","date_gmt":"2022-08-30T15:17:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/kohana-404-custom-page-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:52","modified_gmt":"2022-08-30T15:17:52","slug":"kohana-404-custom-page-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/kohana-404-custom-page-collection-of-common-programming-errors\/","title":{"rendered":"Kohana 404 custom page-Collection of common programming errors"},"content":{"rendered":"<p>here is how I do it with Kohana 3.2<\/p>\n<ul>\n<li>Add exceptions handling stuff in <strong>index.php<\/strong><\/li>\n<\/ul>\n<pre>\n    try\n    {\n        $request = $request-&gt;execute();\n    }\n    catch(Kohana_HTTP_Exception_404 $e)\n    {\n        $request = Request::factory('errors\/404')-&gt;execute();\n    }\n    catch(Exception $e)\n    {\n        $request = Request::factory('errors\/500')-&gt;execute();\n    }\n\n    echo $request-&gt;send_headers()-&gt;body();\n<\/pre>\n<ul>\n<li>Then write Errors controller<\/li>\n<\/ul>\n<pre>\nclass Controller_Errors extends Controller\n{\n    public function __construct($request, $response)\n    {\n        parent::__construct($request, $response);\n    }\n\n    public function action_404()\n    {\n        $this-&gt;response-&gt;body(View::factory('errors\/404'));\n    }\n\n    public function action_500()\n    {\n        $this-&gt;response-&gt;body(View::factory('errors\/500'));\n    }\n}\n<\/pre>\n<ul>\n<li>\n<p>Create 2 corresponding error pages (404.php and 500.php in views\/errors)<\/p>\n<\/li>\n<li>\n<p>Add new route to your bootstrap.php or use default one (depends on you project&#8217;s structure), just make sure Controller_Errors can be reached when exception is thrown<\/p>\n<\/li>\n<li>Now every time you throws the exception in your controller, it will display the custom error page, like this<\/li>\n<\/ul>\n<pre>\nthrow new HTTP_Exception_404;\n<\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:00:40. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>here is how I do it with Kohana 3.2 Add exceptions handling stuff in index.php try { $request = $request-&gt;execute(); } catch(Kohana_HTTP_Exception_404 $e) { $request = Request::factory(&#8216;errors\/404&#8217;)-&gt;execute(); } catch(Exception $e) { $request = Request::factory(&#8216;errors\/500&#8217;)-&gt;execute(); } echo $request-&gt;send_headers()-&gt;body(); Then write Errors controller class Controller_Errors extends Controller { public function __construct($request, $response) { parent::__construct($request, $response); } public [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1598","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1598"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1598\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}