티스토리 뷰
참고 : http://kohanaframework.org/3.2/guide/kohana/tutorials/error-pages
1. 개발중인지 서비스 진행중인지 구분 하는 상수값 지정하기
내 컴퓨터가 아닐 때는 서비스 중 .. 하든가..
if ($_SERVER['HTTP_HOST'] !== 'localhost')
{
Kohana::$environment = Kohana::PRODUCTION;
}
혹은
.htacess 파일 내부에 KOHANA_ENV 지정 하기..
# Set environment
# SetEnv KOHANA_ENV 'production'
2. exception handler 만들기
/application/kohana/exception.php 생성
3. Router 설정하기
bootstrap.php 내부에
4. Errors 컨트롤러 생성
1. 개발중인지 서비스 진행중인지 구분 하는 상수값 지정하기
내 컴퓨터가 아닐 때는 서비스 중 .. 하든가..
if ($_SERVER['HTTP_HOST'] !== 'localhost')
{
Kohana::$environment = Kohana::PRODUCTION;
}
혹은
.htacess 파일 내부에 KOHANA_ENV 지정 하기..
# Set environment
# SetEnv KOHANA_ENV 'production'
2. exception handler 만들기
/application/kohana/exception.php 생성
add(Log::ERROR, parent::text($e));
$attributes = array(
'action' => 500,
'origuri' => rawurlencode(Arr::get($_SERVER, 'REQUEST_URI')),
'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);
}
}
}
}
3. Router 설정하기
bootstrap.php 내부에
/**
* Error router
*/
Route::set('error', 'errors///', array('action' => '[0-9]++', 'origuri' => '.+', 'message' => '.+'))
->defaults(array(
'controller' => 'errors',
'action' => 'index'
));
4. Errors 컨트롤러 생성
request->is_initial())
{
if ($message = rawurldecode($this->request->param('message')))
{
$this->_message = $message;
}
if ($requested_page = rawurldecode($this->request->param('origuri')))
{
$this->_requested_page = $requested_page;
}
}
else
{
// This one was directly requested, don't allow
$this->request->action(404);
// Set the requested page accordingly
$this->_requested_page = Arr::get($_SERVER, 'REQUEST_URI');
}
$this->response->status((int) $this->request->action());
}
/**
* Serves HTTP 404 error page
*/
public function action_404()
{
$this->template->description = 'The requested page not found';
$this->template->keywords = 'not found, 404';
$this->template->title = 'Page not found';
$this->template->content = View::factory('errors/404')
->set('error_message', $this->_message)
->set('requested_page', $this->_requested_page);
}
/**
* Serves HTTP 500 error page
*/
public function action_500()
{
$this->template->description = 'Internal server error occured';
$this->template->keywords = 'server error, 500, internal error, error';
$this->template->title = 'Internal server error occured';
$this->template->content = View::factory('errors/500');
}
}
'웹개발 > Php' 카테고리의 다른 글
| Kohana Request (0) | 2011.08.26 |
|---|---|
| Kohana 3.2 Config 얻기.. (0) | 2011.08.24 |
| PHP 비트 연산자 사용. (0) | 2011.07.17 |
| HTTP 1.1의 Content Length와 Transfer Encoding (0) | 2011.07.11 |
| PHP 알려지지 않은 트릭 몇가지 (0) | 2011.06.30 |
댓글