本文介紹了CakePHP:將所有 404 錯誤重定向到主頁?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
控制器中是否有一種方法或功能可以判斷是否觸發了 404 錯誤?我希望每個人都在首頁重定向,而不是看到 404 頁面.
Is there a way or a function within a controller that tells if a 404 error was triggered? I would like everyone to redirect at the homepage instead of seeing a 404 page.
謝謝!
推薦答案
要捕獲和處理 404 錯誤,需要擴展 ErrorHandler
類并覆蓋 error404
方法.為此,請使用以下代碼創建文件 app/app_error.php
:
To catch and handle 404 errors, you need to extend the ErrorHandler
class and override the error404
method. To do that, create the file app/app_error.php
with the following code:
class AppError extends ErrorHandler {
function error404($params) {
// redirect to homepage
$this->controller->redirect('/');
}
}
手冊
這篇關于CakePHP:將所有 404 錯誤重定向到主頁?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!