을 기반으로, 모두를 캐치하여 오류 페이지로 연결되는 경로를 구현했습니다. 여기 Kohana 3에 대한 지원이 필요하고 404 오류로 바뀌는 모든 경로를 잡으십시오.
은 마지막 경로 내bootstrap.php
나는 시도하고 존재하지 않는 페이지
Kohana_Exception [0]에 갈 때 내가 던진이 예외가 계속하지만
Route::set('default', '<path>', array('path' => '.+')) ->defaults(array( 'controller' => 'errors', 'action' => '404', ));
: 필수 경로 매개 변수가 전달되지 않음 : 경로
<path>
세그먼트를 선택적으로 만들면 즉
Route::set('home', '')
->defaults(array(
'controller' => 'home',
'action' => 'index',
));
홈 경로는 첫번째 정의 ... 다음 그냥있는 home
경로를로드하는 것) 괄호에 포장. 모든 경로는 다음이 404 오류 세트를 표시해야합니다
$request = Request::instance();
try {
// Attempt to execute the response
$request->execute();
} catch (Exception $e) {
if (Kohana::$environment === Kohana::DEVELOPMENT) throw $e;
// Log the error
Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e));
// Create a 404 response
$request->status = 404;
$request->response = Request::factory(Route::get('default')->uri())->execute();
}
$request->send_headers();
echo $request->response;
처럼 내 주요 요청을 실행,하지만 난 캡처에 요청을 전송하여 가정 내 오류 컨트롤러에서.
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Errors extends Controller_Base {
public function before() {
parent::before();
}
public function action_404() {
$this->bodyClass[] = '404';
$this->internalView = View::factory('internal/not_found');
$longTitle = 'Page Not Found';
$this->titlePrefix = $longTitle;
}
}
왜 내 404 오류 페이지가 표시되지 않습니까?
Exception404를 만들었습니까? 아니면 Kohana가 정의한 것입니까? 귀하의 답변도 주셔서 감사합니다 :) – alex
이것은 내 것입니다. 나는 그 코드를 대답에 추가했다 – zerkms
감사합니다 힙! 이것은 재미 있고 도움이되므로 받아 들일 것입니다. – alex