• About Me




    Lily@Melbourne, Australia

    Login

  • Follow 静水深流 || Still waters run deep on WordPress.com
  • Archives

CakePHP: 定制个性化的错误信息

首先还是要感谢google, 你总能得到帮助,找不到答案的主要原因是你没有问对问题。可是转念一想,问出对的问题的前提是你很知道你想要什么,如果这是一个很模糊的想法,相应地回答也很宽泛不着边际。

原文连接:Custom 404 Not Found Error Pages in CakePHP 2.0+

1,更新app/Config/core.php

Configure::write(‘Exception’, array(
‘handler’ => ‘ErrorHandler::handleException’,
‘renderer’ => ‘AppExceptionRenderer‘,  //这样我们指向自定义exception了
‘log’ => true
));

2, 创建/app/Lib/Error/AppExceptionRenderer.php //注意到它的命名和在core里指向的得一样

文件下载>>
具体说明可以参加前面提到的连接,我就不罗嗦了。

3, 创建/app/View/Errors/error404.ctp //注意到它的命名和在AppExceptionRenderer.php里指向的得一样

code很简单:

<div class=”error”>
<h2>Whoops! We can not find your page…</h2>
<h2>404</h2>
</div>

Error404

Error404

 

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: