cakephp: 3.x: Fallback error templates to non ext ones
In 3.1 latest, when trying to work with extensions, one runs into:
Fatal error: [Cake\View\Exception\MissingTemplateException] Template file "Error\pdf\error500.ctp" is missing
When opening some /controller/action.pdf URL.
Sure, I don’t want to have custom error templates for all extensions. My assumption would be that it will fallback to non-ext ones (Error\error500.ctp) from Cake itself, when this specific layout is not found. This would make it more DRY, because I only have to add error templates for the cases where I want to change error behavior (or stay inside the current type) based on the extension.
After some debugging I found out that it wanted to throw an error 'Error\pdf\missing_helper' because of a missing helper, but ended up throwing fatals because of missing error layout it should not necessarily expect in the first place.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 21 (20 by maintainers)
If you have a patch in mind, a pull request would be great. I think this isn’t as simple as it initially seems and we run the risk of disrupting custom view classes.
I’ve learned not to make assumptions about what could be safe around application code.
Getting the ‘correct’ view class is of course the challenge here. You might think that we could use
Viewbut I’m sure there exists an application out there that only has twig template for example.I would like to reopen this issue. It is a constant pain when developing with extensions…
a) admin prefix b) ics extension
It won’t even output the error because the only thing logged is the missing template here. So it is double-problematic. If the logs at least contained the actual error as part of the trace it might still be acceptable as of right now. But this way we definitly need to fix it. Here also no custom view class manipulates the error template paths.
I cant and wont put error templates for all possible scenarios inside those many subfolders for each extension and prefix. What I would like to see is the following:
Any objections? It is only for this view rendering - and in this case even only for debug mode - so no harm IMO.
That’s not possible. The error handling code resets the view template path. We could overwrite the templatePath after creating the view class, but we risk breaking any custom pathing that views do.