假設有人打在URL http://mysite.com/comments/view/13CakePHP的控制器/行動的問題
但這absentaction沒有出現在評論控制器。
然後獲取正常的錯誤一樣,=>
Error: The action view is not defined in controller CommentsController
Error: Create CommentsController::view() in file: app/controllers/comments_controller.php.
<?php
class CommentsController extends AppController {
var $name = 'Comments';
function view() {
}
}
?>
Notice: If you want to customize this error message, create app/views/errors/missing_action.ctp
我想要做的是,如果有人點擊網址http://mysite.com/comments/view/13,如果動作不存在,那麼它會重定向到http://mysite.com/。
我該如何處理未知/缺席的操作?
查看[CakePHP API](http://api13.cakephp.org/class/error-handler)以獲取更多詳細信息 – Franquis
我剛剛使用了這個=><?php class AppError擴展ErrorHandler函數missingAction($ params){this-> controller-> redirect(array('controller'=>'posts','action'=>'index')); \t \t} } ?>它正在工作。 – shibly
很高興知道:) – Franquis