ZF2-214: TemplatePathStack::resolve - view script path not chosen correctly

Description

use case:

  • 2 existing modules, both have a 'view' folder inside the 'src' folder
  • both modules have a controller 'IndexController' and action 'index'
  • different routes to each IndexController::indexAction exist
  • the module specific view path is added via module.config.php of its module to TemplatePathStack

bug:

  • TemplatePathStack::resolve does choose the first view path where a /index/index.phtml is found

So the order of paths in TemplatePathStack (result of config merging) determines the chosen view script.

involved code (in my case):

PhpRenderer::render downto PhpRenderer::resolver downto AggregateResolver::resolve downto TemplatePathStack::resolve

What should happen imho, is that the routeMatch controller namespace defines the view script path somehow.

Thank you for having a look at this.

Best regards, Jade

Comments

It's actually operating exactly as designed; order of registration does matter.

That said, we're planning to alter how the view resolution works for beta4 so that the template name includes the module name. This will mean, however, pushing view templates down one more level in the view directory:


view/
    /
        /
            .phtml

I'm closing this as "not an issue", as the TemplatePathStack is working as intended. However, if you want to open an issue indicating the desired behavior against the Zend\View or Zend\Mvc component, please do so; that said, it's already designated for beta4.