Created
May 28, 2012 13:58
-
-
Save rockymontana/2819337 to your computer and use it in GitHub Desktop.
403 costum error problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output | |
method="html" | |
encoding="utf-8" | |
omit-xml-declaration="yes" | |
doctype-system="about:legacy-compat" | |
/> | |
<xsl:include href="../inc.default.xsl" /> | |
<xsl:template match="/"> | |
<xsl:call-template name="default_template" /> | |
</xsl:template> | |
<xsl:template match="/root/content"> | |
<div class="large-content-box"> | |
<h1>403 Forbidden</h1> | |
<p> | |
<xsl:value-of select="errors/error/message" /><br /> | |
Go to the <a href="/">start</a> page. | |
</p> | |
</div> | |
</xsl:template> | |
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Error router | |
*/ | |
Route::set('error', 'error/<action>(/<message>)', array('action' => '[0-9]++', 'message' => '.+')) | |
->defaults(array( | |
'controller' => 'error', | |
)); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
class Controller_Error extends Controller_Uv | |
{ | |
var $errors; | |
public function before() | |
{ | |
parent::before(); | |
if ( empty($this->xml_content_errors) OR ! isset($this->xml_content_errors)) | |
$this->xml_content_errors = $this->xml_content->appendChild($this->dom->createElement('errors')); | |
// Internal request only! | |
if (Request::$initial !== Request::$current) | |
{ | |
if ($message = rawurldecode($this->request->param('message'))) | |
{ | |
$this->errors = array(array('message' => $message, 'id' => $this->request->action())); | |
} | |
} | |
else | |
{ | |
$this->request->action(404); | |
} | |
$this->response->status((int) $this->request->action()); | |
} | |
public function action_403() | |
{ | |
$this->errors = array('id' => $this->request->action(), 'message' => urldecode($this->request->params('id'))); | |
$this->xslt_stylesheet = 'errors/403'; | |
xml::to_XML($this->errors, $this->xml_content_errors, 'error', 'id'); | |
// HTTP Status code. | |
$this->response->status(403); | |
} | |
public function action_404() | |
{ | |
$this->xslt_stylesheet = 'errors/404'; | |
xml::to_XML($this->errors, $this->xml_content_errors, 'error', 'id'); | |
// HTTP Status code. | |
$this->response->status(404); | |
} | |
public function action_500() | |
{ | |
$this->xslt_stylesheet = 'errors/500'; | |
xml::to_XML($this->errors, $this->xml_content_errors, 'error', 'id'); | |
// HTTP Status code. | |
$this->response->status(500); | |
} | |
public function action_503() | |
{ | |
$this->xslt_stylesheet = 'errors/500'; | |
xml::to_XML($this->errors, $this->xml_content_errors, 'error', 'id'); | |
// HTTP Status code. | |
$this->response->status(503); | |
} | |
public function after() | |
{ | |
die($this->response->status()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
class Kohana_Exception extends Kohana_Kohana_Exception { | |
public static function handler(Exception $e) | |
{ | |
if (Kohana::DEVELOPMENT === Kohana::$environment) | |
{ | |
parent::handler($e); | |
} | |
else | |
{ | |
try | |
{ | |
Kohana::$log->add(Log::ERROR, parent::text($e)); | |
$attributes = array | |
( | |
'action' => 500, | |
'message' => rawurlencode($e->getMessage()) | |
); | |
if ($e instanceof HTTP_Exception) | |
{ | |
$attributes['action'] = $e->getCode(); | |
} | |
// Error sub-request. | |
echo Request::factory(Route::get('error')->uri($attributes)) | |
->execute() | |
->send_headers() | |
->body(); | |
} | |
catch (Exception $e) | |
{ | |
// Clean the output buffer if one exists | |
ob_get_level() and ob_clean(); | |
// Display the exception text | |
echo parent::text($e); | |
// Exit with an error status | |
exit(1); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment