ZF-2745: Add ViewRenderer inflection awareness to Zend_View

Description

Currently, there are two different conventions for resolving view scripts:

  • With the ViewRenderer, the action alone is enough for resolving most view scripts; in fact, unless you call out to special methods of the ViewRenderer such as renderScript(), you never need to consider the controller directory or view suffix.
  • Inside the view script itself, however, you need to be aware of the controller directory and view suffix, as well as where other view scripts and partials reside within the view script paths.

We should add functionality to Zend_View to allow view script resolution using the ViewRenderer or separate this coupling into a separate class that both the ViewRenderer and Zend_View could utilize. This could be on by default, unless no controller directories are found in Zend_Controller_Front (or unless the developer has disabled such functionality).

Comments

Two things I think could be useful when addressing this:

Optionally, be able to not use script resolution and access methods similar to renderScript() if you want to include specific views.

Add the directory of the calling file to the include path so subsequent nested calls don't have to specify the entire path again. For example, in a view, if we do $this->render('../../some/far/off/place/outside/include/path/testfile.suf') and in testfile.suf, we do a $this->render('test2.phtml') where test2.phtml is located in the ../../some/far/off/place/outside/include/path/ directory. Basically, if we could add that directory to the include path and continue to use the new script resolution, that would be great. So, we could use $this->render('test2') in testfile.suf and it would work. Maybe in render method of Zend_View/Abstract or maybe in _run method of Zend_View. Anyways, in one of those final methods for rendering, you could push the include path to include dirname($script).

Please categorize/fix as needed.

This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.

Updating project management info.

This should actually be done in a helper, not within Zend_View itself. Doing it in a helper allows Zend_View to maintain minimal dependencies, and helpers are the appropriate place to provide coupling to other components.

This needs a full proposal before development.

If you need ViewRenderer awareness inside your view script, why now just use Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer') to retrieve it?

Can this issue be closed as "Wont' Fix"? AFAIK, there are no plans to implement this in 1.12, and Ralph has provided a possible workaround (though providing a convenience view helper would make things cleaner)