首页 \ 问答 \ CakePHP 2.0在发生异常时不加载自定义帮助程序(CakePHP 2.0 not loading custom helpers when exceptions occur)

CakePHP 2.0在发生异常时不加载自定义帮助程序(CakePHP 2.0 not loading custom helpers when exceptions occur)

我正在创建一个CakePHP应用程序,但只要抛出异常(例如安全异常等),就不会加载任何自定义助手。 这会导致页面出错并显示帮助程序未加载错误而不是异常。

我的助手都在AppController中加载,我大部分时间都没有问题。 我刚刚添加了安全组件以防止CSRF,但每当我模拟CSRF时,我都会收到以下错误:

    Notice (8): Undefined property: View::$HelperName [CORE/Cake/View/View.php, line 804]

    View::__get() - CORE/Cake/View/View.php, line 804
    include - APP/View/Layouts/default.ctp, line 105
    View::_evaluate() - CORE/Cake/View/View.php, line 908
    View::_render() - CORE/Cake/View/View.php, line 872
    View::renderLayout() - CORE/Cake/View/View.php, line 527
    View::render() - CORE/Cake/View/View.php, line 471
    Controller::render() - CORE/Cake/Controller/Controller.php, line 959
    ExceptionRenderer::_outputMessage() - CORE/Cake/Error/ExceptionRenderer.php, line 263
    ExceptionRenderer::error400() - CORE/Cake/Error/ExceptionRenderer.php, line 209
    ExceptionRenderer::render() - CORE/Cake/Error/ExceptionRenderer.php, line 165
    ErrorHandler::handleException() - CORE/Cake/Error/ErrorHandler.php, line 127
    [main] - [internal], line ??

它只是我的定制助手,而不是核心助手。 我想显示异常错误,并将自定义帮助器作为帮助包含在布局的核心部分中。

你能给予的任何帮助都会很棒。


I'm creating a CakePHP application but whenever an Exception is thrown (e.g. Security exceptions amongst others) any custom helpers are not loaded. This causes the page to error and the helper not loaded error is displayed instead of the exception.

My helpers are all loaded in AppController and I have no problem with them most of the time. I've just added the Security component to protect against CSRF but whenever I simulate CSRF, I get the following error:

    Notice (8): Undefined property: View::$HelperName [CORE/Cake/View/View.php, line 804]

    View::__get() - CORE/Cake/View/View.php, line 804
    include - APP/View/Layouts/default.ctp, line 105
    View::_evaluate() - CORE/Cake/View/View.php, line 908
    View::_render() - CORE/Cake/View/View.php, line 872
    View::renderLayout() - CORE/Cake/View/View.php, line 527
    View::render() - CORE/Cake/View/View.php, line 471
    Controller::render() - CORE/Cake/Controller/Controller.php, line 959
    ExceptionRenderer::_outputMessage() - CORE/Cake/Error/ExceptionRenderer.php, line 263
    ExceptionRenderer::error400() - CORE/Cake/Error/ExceptionRenderer.php, line 209
    ExceptionRenderer::render() - CORE/Cake/Error/ExceptionRenderer.php, line 165
    ErrorHandler::handleException() - CORE/Cake/Error/ErrorHandler.php, line 127
    [main] - [internal], line ??

It is only ever my custom helpers though, never the core ones. I want to display the exception error and for the custom helper to be included as helps with a core part of the layout.

Any help you can give will be fantastic.


原文:https://stackoverflow.com/questions/10874770
更新时间:2022-05-11 06:05

最满意答案

正如评论中所提到的,这是一个现已修复的错误 - cakephp.lighthouseapp.com/projects/42648/tickets/2274 (感谢tigrang)。


As mentioned in the comments, this was a bug which has now been fixed - cakephp.lighthouseapp.com/projects/42648/tickets/2274 (Thanks to tigrang).

相关问答

更多
  • 尝试这个: /app/Config/core.php 异常渲染需要设置为AppExceptionRender 。 例: Configure::write('Exception', array( 'handler' => 'ErrorHandler::handleException', 'renderer' => 'AppExceptionRenderer', 'log' => true )); /app/Controller/ErrorsController ...
  • 供应商无法在CakePHP中使用App::uses()加载,这是因为CakePHP不能期望外部库遵循关于文件夹和文件命名的相同标准。 您仍然可以像在框架的1.3版中一样使用App::import('Vendor', ...) 。 现在,如果你考虑一下,为供应商使用App::import()是有点愚蠢的。 这仅仅是require_once()一个昂贵的,冗长的和非常愚蠢的包装。 在2.0中,我们实际上鼓励人们为Vendor库使用require或require_once。 您可以使用App::path('Ven ...
  • 我终于设法得出了这个想法! 从github看代码,我已经设法让它工作。 这是我的AppExceptionRenderer.php: App::uses('ExceptionRenderer', 'Error'); class AppExceptionRenderer extends ExceptionRenderer { public function missingController($error) { $this->controller->render('/Errors/er ...
  • 正如评论中所提到的,这是一个现已修复的错误 - cakephp.lighthouseapp.com/projects/42648/tickets/2274 (感谢tigrang)。 As mentioned in the comments, this was a bug which has now been fixed - cakephp.lighthouseapp.com/projects/42648/tickets/2274 (Thanks to tigrang).
  • 关闭调试后,所有错误都将转换为400或500错误。 因此,您只需根据需要自定义您的app/View/Errors/error400.ctp和app/View/Errors/error500.ctp 。 With debug turned off all your error are converted to either 400 or 500 errors. So you just need to customize your app/View/Errors/error400.ctp and app/Vie ...
  • 它真的很重要,因为碰撞可能会“消灭”你对助手的访问。 假设我有一个名为Form的模型,并在获得许多记录后决定在我的视图中执行类似的操作。 foreach ($forms as $form) { echo $form['Form']['name'] . '
    '; } 看看那里发生了什么? 我不小心覆盖了$form变量,基本上丢失了我的FormHelper 。 现在的标准是在视图中通过$this访问所有助手。 It really only matters because of the poss ...
  • 我把名字从图书馆改为贝瑞(我的名字)。 显然你不能称之为图书馆。 可能在Cake的其他地方使用过。 I changed the name from Library to Berry (My first name). Apparently you can't call it Library. Probably used somewhere else in Cake.
  • cake 2.x在http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/part-two.html中使用AclExtras作为解释,进行设置。 cake 2.x uses AclExtras as explaind in http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-applicat ...
  • 有点晚,但我认为对于具有相同问题的其他用户进行进一步的解释可能会有用。 实际上,使用您的解决方案,您依赖于位于全局命名空间中的本机PHP SPL Exception类。 要使用Cake的基本Exception类,您错过了添加 use Cake\Core\Exception\Exception; 在src/Exceptions/DuplicateConfigurationException.php中加载Cake Exception类构造函数。 见蛋糕书 您的代码正在运行,因为Cake正在以与其自己的Exce ...
  • 仔细查看API文档: API> CakeRoute :: parse() parse()方法应该在成功时返回一个解析参数数组(即$params ),或者在失败时返回false 。 Have a closer look at the API documenation: API > CakeRoute::parse() The parse() method is supposed to return an array of parsed parameters (ie $params) on success, o ...

相关文章

更多

最新问答

更多
  • 如何重新加载下拉列表(How to reload dropdownlist)
  • RStudio:在脚本中保留特殊字符(RStudio: keeping special characters in a script)
  • Powershell的“GetLatest”不会在新的TFS工作区上下载文件(“GetLatest” with Powershell doesn't download files on new TFS workspace)
  • 我如何让JS识别一个由字符组成的数组?(How do I get JS to recognise an array insted of characters?)
  • EF从存储过程中急切加载(EF eager loading from stored procedure)
  • 将输出文件添加到Python扩展(Adding output file to Python extension)
  • 淮北职业技术学院电脑应用专业咋样?
  • 更改默认扩展面板箭头的箭头样式(Change arrow style for default expansion panel arrow)
  • 芜湖计算机(计算机)培训机构(培训班,学校)哪家好
  • 致命错误:使用clang-llvm ASTMatcher时未找到'stddef.h'文件(fatal error: 'stddef.h' file not found when using clang-llvm ASTMatcher)
  • 内容的.NET缓存(Contentful .NET caching)
  • 客户端没有发生WCF回调(WCF callback is not happening in client)
  • 使用friend在全局范围内调用类成员函数会产生27个错误(Calling a Class member function in Global Scope using friend Gives 27 ERRORS)
  • 如何绑定到WPF中的另一个控件属性(How to Bind to Another Control Property in WPF)
  • 南华大学电脑专业,就业好不好
  • 是否存在泄密文件的官方(或常见)文件扩展名或后缀?(Is there an official (or common) file extention or suffix for deflated files?)
  • 在SVM python中只训练一次(Training only once in SVM python)
  • 淘汰自定义绑定光滑js无法正常工作(knockout custom binding for slick js not working)
  • 似乎无法正确地抓住网站“福布斯”(Can't seem to scrape the website “Forbes” properly)
  • 无法使用boto.rds2从describe_instance方法检索有关db实例的信息(Not able to retrieve information about db instances from the describe_instance method using boto.rds2)
  • 转换为英国日期格式问题(Convert to british date format issue)
  • 在表中列出不同的元组(10种方法)(List distinct tuples in a table(SQL query)(10 ways))
  • OrientDB查询比较(OrientDB query compare)
  • 全局变量有什么不好?(What is so bad about global variables? [duplicate])
  • 为什么JavaMail Transport.send()是一个静态方法?(Why is JavaMail Transport.send() a static method?)
  • 获取最近3个Instagram图像张贴在一个地方(Get last 3 instagram images posted in a place)
  • 使用libnfc格式化/读/写NDEF Mifare 1K卡(Format/Read/Write NDEF Mifare 1K Card using libnfc)
  • 阻止谷歌索引特定图像(Block Google from indexing a particular image)
  • 消息模板接收让Dispatcher没有订阅频道(Message Template receive gives Dispatcher has no subscribers for channel)
  • OpenShift:使用自定义节点版本(OpenShift: Use custom node version)