1

我看過shadowhand(Kohana目前的主要人物)如何設置他的bootstrap.php文件來處理GitHub的異常。發送404s到Kohana的自定義路由3

我想,「這很酷」,所以我加入了類似的東西。

但是,我不想提供視圖,而是將請求發送到不同的路由(或至少將其指向控制器/操作對)。

因此,這部分在GitHub上

// Create a 404 response 
$request->status = 404; 
$request->response = View::factory('template') 
->set('title', '404') 
->set('content', View::factory('errors/404')); 

會是這樣的(當然是僞代碼)

// Create a 404 response 
$request->status = 404; 
$request->response = Route::get('404_error'); // which will map to a route outlined above in bootstrap.php 

我怎樣才能做到這一點?由於

回答

4

使用支持::工廠的URI:

$request->response = Request::factory('error/404')->execute(); 

或者與路線:

$request->response = Request::factory(Route::get('error_404')->uri())->execute(); 
+2

最後一行,則'路線::得到()''需要 - > URI ()'不是嗎? – alex 2010-03-02 05:36:33

+0

是的,更正。謝謝alex。 – rick 2010-03-03 01:43:35