ZF2-193: Zend\View\Resolver\TemplatePathStack suffix behavior is too restrictive for multiple suffixes

Issue Type: Patch Created: 2012-03-04T16:20:48.000+0000 Last Updated: 2012-10-08T20:15:26.000+0000 Status: Closed Fix version(s): Reporter: Yonni Mendes (yonman) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend\View

  • View_Helper
  • view
  • viewscript

Related issues: Attachments:


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

<pre class="highlight">
// 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:

<pre class="highlight">
// 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


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:

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.