本文介绍了CakePHP-ErrorHandler无法扩展AppController的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道为什么我的错误页面导致了网站的某些页面没有渲染,但是后来我意识到这是因为AppError扩展了ErrorHandler代替AppController.这引起了一些变数我在AppController的beforeFilter方法中设置的不发送给风景.由于我无法从AppError访问会话变量,因此我以为我也许可以摆脱使用classRegistry的麻烦实例化可以复制的内容,然后简单地将其粘贴我其余的代码来自AppController的beforeFilter ...,但这不起作用,也似乎不是一个非常优雅的解决方案.有谁对什么有任何线索将是解决此问题的最佳方法?谢谢大卫.

I had been wondering why my error page caused certain pages of my sitenot to render, but then I realized that it's because AppError extendsErrorHandler instead of AppController. This caused some variablesthat I set in AppController's beforeFilter method not to be sent tothe view. Since I can't access session variables from AppError, Ithought that I might be able to get away with using the classRegistryto instantiate something that could and simply copying and pasting therest of my code from AppController's beforeFilter... but that isn't working, nor does it seem like a very elegant fix. Does anyone have any clues as to whatwould be the best way to approach this? Thanks, David.

推荐答案

您的AppError类具有一个控制器实例.您可以手动调用beforeFilter:

Your AppError class has a controller instance. You can call the beforeFilter manually:

<?php
class AppError extends ErrorHandler {
  function error404() {
    $this->controller->beforeFilter();
    parent::error404();
  }
}
?>

这篇关于CakePHP-ErrorHandler无法扩展AppController的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 22:47