【问题标题】:Unknown error on attempt to throw 404 page尝试抛出 404 页面时出现未知错误
【发布时间】:2010-11-28 18:32:26
【问题描述】:

我的控制器中有一个处理通用页面请求的方法,适用于我的公共页面。当我无法匹配 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, line 10]

“$this->layout = '空白';”是我尝试重定向到不包含任何 CSS、JS 等的空白布局文件。但它完全忽略了这一点并加载了包含 JS 的默认模板。我猜测加载404页面的错误例程无法访问这些方法,这是错误的根源。

但我不知道如何处理这个错误。

【问题讨论】:

    标签: cakephp php cakephp-1.2


    【解决方案1】:

    首先,您的代码中有一个小错误。 cakeError() 的第二个参数已经是一个数组。应该是:

    $this->cakeError('error', $opts);
    

    第二,可以设置

    $this->layout = false;
    

    如果你想要一个空白布局。

    【讨论】:

      猜你喜欢
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多