ZF2-193: Zend\View\Resolver\TemplatePathStack suffix behavior is too restrictive for multiple suffixes
Description
In a project where view scripts can come in multiple flavors (.pjson, .pxml, .phtml), the current defaultSuffix behavior is too restrictive and cannot be easily modified on-the-fly.
I have an application which has a UI and API calls that may return different formats of responses (json and xml). I named the view scripts .p so as to keep my controllers uniform and only change the suffix in the renderer (back in beta 2). To make things a bit more complex, I some times call these view scripts into rendering by using the Partial View Helper using their true filename (such as 'IssueWebAPI/monitorGetIssues.pjson'). I work around this issue by naming the file .pjson.phtml, which seems inelegant.
The original behaviour fails to work in beta 3, seems to be because of lines 316-320 in Zend/View/Resolver/TemplatePathStack.php
// Ensure we have the expected file extension
$defaultSuffix = $this->getDefaultSuffix();
if (pathinfo($name, PATHINFO_EXTENSION) != $defaultSuffix) {;
$name .= '.' . $defaultSuffix;
}
No matter which suffix I specify (excpet for phtml), .phtml is always appended to the file-name and the resolver fails to retrieve the file.
Instead, I suggest the following behavior:
// Ensure we have the expected file extension
$defaultSuffix = $this->getDefaultSuffix();
if (pathinfo($name, PATHINFO_EXTENSION) == '') {
$name .= '.' . $defaultSuffix;
}
This behaviour attaches the default suffix if no suffix was specified (the desired behaviour) but leaves the file-name alone if some other suffix is in place
Comments
Posted by Ralph Schindler (ralph) on 2012-10-08T20:15:26.000+0000
This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2459