CI4
[코드이그나이터] 사용자 정의 예외
으누아빠
2020. 8. 28. 17:20
반응형
CI4 > Tutorial > 정적페이지(Static pages) > 사용자 정의 예외
출처:
http://ci4doc.cikorea.net/general/errors.html#id5
PageNotFoundException
404, Page Not Found 오류를 알리는데 사용
"/app/views/errors/html/error_404.php" 에 있는 view를 노출함
Config/Routes.php 에서 404 Override를 하면 기본 404페이지 대신 원하는 페이지를 불러올 수 있음
<?php
if (! $page = $pageModel->find($id))
{
throw new \CodeIgniter\Exceptions\PageNotFoundException();
}
404 페이지 override
app/Config/routes.php
<?php
// Would execute the show404 method of the App\Errors class
$routes->set404Override('App\Errors::show404');
// Will display a custom view
$routes->set404Override(function()
{
echo view('my_errors/not_found.html');
});
ConfigException
클래스의 값이 유효하지 않거나, 구성 클래스가 올바른 유형이 아닌 경우에 사용
<?php
throw new \CodeIgniter\Exceptions\ConfigException();
DatabaseException
데이터베이스 연결을 작성할 수 없거나 일시적으로 유실 된 경우와 같은 데이터베이스 오류에 대해 사용
<?php
throw new \CodeIgniter\Database\Exceptions\DatabaseException();
RedirectException
특정 경로 또는 URL 경로로 리다이렉트 할때 사용
<?php
throw new \CodeIgniter\Router\Exceptions\RedirectException($route);