2012-11-14 1 views
0

나는 mdskinner 덕분에 how-to-setup-a-custom-404-page-for-a-kohana-v3-app의 솔루션을 사용했습니다. 따라서 작업 코드는 다음과 같습니다.Kohana3의 404 사용자 정의 페이지를 동적으로로드하는 방법은 무엇입니까?

Kohana_Exception::$error_view = 'kohana/404';//bootstrap.php 

and the view file path is system/views/kohana/404.php 

불행히도 404 페이지는 정적 페이지입니다. 하지만 컨트롤러와 뷰를 사용하여 다른 페이지와 마찬가지로 동적으로 바닥 글을 동적으로로드하려고합니다. 404 사용자 정의 페이지에서 가능합니까?

답변

0

네, 쉽게 할 수 있습니다. 3.2 - http://kohanaframework.org/3.2/guide/kohana/tutorials/error-pages에 대한 공식 가이드 또는 Lysender의 멋진 블로그 게시물 - http://blog.lysender.com/2010/08/kohana-404-pages/을 사용하십시오 (이것은 실제로 3.1 버전이지만 3.2와 3.1 사이의 변경 사항은 그리 크지 않습니다). 당신의 index.php에서

+0

같은 요청을 실행하고 에코 사이 try/catch 블록을 넣어? 참조 : http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-where other-really-good-answers –

1

, 당신은 당신이 적어도 대신 외부 페이지에 링크의 대답을 붙여 안이

$request = Request::factory(); 

try 
{ 
    $response = $request->execute(); 
} 
catch (Exception $exc) 
{ 
    if ($exc instanceof HTTP_Exception && $exc->getCode() === 404) 
    { 
    $response = Request::factory('your404route')->execute()->status(404); 
    } else { 
    throw $exc; 
    } 
} 

echo 
    $response 
    ->send_headers() 
    ->body(); 
관련 문제