Cakephp - how to make error pages have its own layouts?

后端 未结 6 1383
被撕碎了的回忆
被撕碎了的回忆 2021-02-13 16:00

I wanna have a different layout for the page not found 404 page. How can i set a different layout for that page?

6条回答
  •  独厮守ぢ
    2021-02-13 16:30

    This simplest way I know of is to create this function in your AppController:

    function appError($method, $messages)
    {
    }
    

    You can then do whatever you want with the error, display it however you like, or not display it at all, send an email etc.. (I'm not sure if this method if still valid.)

    There is also an option of creating app_error.php in your app root, with class AppError extends ErrorHandler in it, which enables you to override all kinds of errors. But I haven't done this yet, so I can't tell you more about it.

    See cake/libs/error.php and cake/libs/object.php and of course The Book for more info.

    Edit: Forgot to mention, once you caught the error, there's nothing preventing you to - for example - store the error in session, redirect to your "error handling controller", and then display it in your controller however you want.

提交回复
热议问题