尝试抛出 404 页面时出现未知错误
我的控制器中有一个方法可以处理通用页面请求,适用于我的公共页面。当我无法匹配 URL 中的内容和我所知道的静态内容页面时,我想抛出 404。
所以我这样做:
$opts = array(
'name' => 'Some message',
'code' => 404,
'message' => 'Your message here',
'base' => $this->base
);
$this->layout = 'blank';
$this->cakeError('error', array($opts));
问题是我在 404 请求上收到此错误:
注意(8):未定义的变量:javascript [APP\views\layouts\default.ctp,第 10 行]
"$this->layout = 'blank';"我尝试重定向到一个不包含任何 CSS、JS 等的空白布局文件。但它完全忽略了这一点并加载包含 JS 的默认模板。我猜测加载 404 页面的错误例程无法访问这些方法,这就是错误的根源。
但我不知道如何处理这个错误。
I have a method in my controller that handles generic page requests, meant for my public pages. I want to throw a 404 when I can't match what is in the URL and what I know are the static content pages.
So I do this:
$opts = array(
'name' => 'Some message',
'code' => 404,
'message' => 'Your message here',
'base' => $this->base
);
$this->layout = 'blank';
$this->cakeError('error', array($opts));
The problem is I get this error on a 404 request:
Notice (8): Undefined variable: javascript [APP\views\layouts\default.ctp, line 10]
The "$this->layout = 'blank';" is my attempt to redirect to a blank layout file that doens't include any CSS, JS, etc. But it's ignoring this completely and loading the default template, which has JS includes. I'm guessing that the error routines that load 404 pages don't have access to these methods, which is the source of the error.
But I can't figure out how deal with this error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您的代码中有一个小错误。 cakeError() 的第二个参数已经是一个数组。应该是:
其次,你可以设置
是否想要空白布局。
First, there's a small bug in your code. Your second parameter to cakeError() is already an array. It should be:
Second, you can set
if you want a blank layout.