このドキュメントに基づいて、エラー ページにルーティングするすべてのキャッチルートを実装しました。
これが私の最後のルートですbootstrap.php
Route::set('default', '<path>', array('path' => '.+'))
->defaults(array(
'controller' => 'errors',
'action' => '404',
));
ただし、存在しないページに移動しようとすると、この例外がスローされ続けます
Kohana_Exception [ 0 ]: 必要なルート パラメータが渡されませんでした: パス
セグメントをオプションにする<path>
(つまり、括弧で囲む) と、home
ルートが読み込まれるように見えますが、これは...
Route::set('home', '')
->defaults(array(
'controller' => 'home',
'action' => 'index',
));
ホーム ルートが最初に定義されます。
私はそのように私の主な要求を実行します
$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;
これは、404 ヘッダーがブラウザーに送信されることを意味しますが、リクエストをすべてのキャプチャー ルートに送信すると、エラー コントローラーに設定された 404 エラーが表示されるはずです。
<?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 エラー ページが表示されないのはなぜですか?