【问题标题】:CakePHP: error views from pluginCakePHP:来自插件的错误视图
【发布时间】:2015-02-03 20:33:17
【问题描述】:

对于我的应用,我正在尝试使用插件中的视图错误。因此,可以在此处找到错误视图:

app/Plugin/MyPlugin/View/Errors/

相反,我会使用应用程序中的布局(“default.ctp”或更好的“error.ctp”)。只能从插件中获取错误视图。

我试过了,但我找不到任何例子,我知道我可能需要重写 ExceptionRenderer 类,但我没有找到好的例子。谁能给我一些建议?

谢谢

【问题讨论】:

  • 几个月后,我仍然有这个问题,我还没有找到解决办法。很简单:为每个应用程序创建错误视图似乎没用。所以我想创建一个带有常见错误视图的插件。怎么办?

标签: cakephp view


【解决方案1】:

解决了!

class MyExceptionRenderer extends ExceptionRenderer {
    /**
     * Generate the response using the controller object.
     * @param string $template The template to render.
     */
    protected function _outputMessage($template) {
        $template = sprintf('%s.%s', 'MyPlugin', $template);

        parent::_outputMessage($template);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多