ZF-9575: Hardcoded paths in the ZF Library - 'views'

Issue Type: Bug Created: 2010-03-30T10:06:51.000+0000 Last Updated: 2010-03-30T14:22:30.000+0000 Status: Resolved Fix version(s): Reporter: matthew ishii (mishii1776) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

  • Zend_Db
  • Zend_Gdata
  • Zend_Service_Amazon
  • Zend_Service_SlideShare
  • Zend_Tool
  • Zend_View

Related issues: Attachments:


I had thought I had full control over my directory structure. As such I very much dislike naming the MVC directories in the plural and so named them as 'controller', 'model', and 'view'. To my dismay, there are hardcoded path references within the ZF library to 'views'.

In my mind this is a coupling that shouldnt be there. Lets make this more flexible shall we? Convention is OK, but something like this makes little sense when all other directories are allowed to be named whatever the developer chooses. Why is the view directory the only one required to be named something specific?

Also please consider the bootstrap file sets the front controller's 'controller' directory. Similarly there should be a way to set the view directory as well.


Posted by Matthew Weier O'Phinney (matthew) on 2010-03-30T11:00:47.000+0000

All of these are configurable.

  • To modify where the ViewRenderer looks for view scripts, configure it; try adding the following to a resource initializer in your bootstrap:

      $vr = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
  • Provide an alternate resource autoloader to your module bootstraps; this can be done to remove pluralizations, add extra mappings, and more. As an example, the following defines a new resource autoloader, a base bootstrap class that uses that resource autoloader, and a bootstrap:

      My_Resource_Autoloader extends Zend_Application_Module_Autoloader
          public function initDefaultResourceTypes()
              $this->addResourceType('viewhelper', 'View_Helper', 'view/helper');
              // etc.
      My_Bootstrap extends Zend_Application_Module_Bootstrap
          public function getResourceAutoloader()
              if ((null === $this->_resourceLoader)
                  && (false !== ($namespace = $this->getAppNamespace()))
              ) {
                  $r    = new ReflectionClass($this);
                  $path = $r->getFileName();
                  $this->setResourceLoader(new My_Resource_Autoloader(array(
                      'namespace' => $namespace,
                      'basePath'  => dirname($path),
              return $this->_resourceLoader;
      Somemodule_Bootstrap extends My_Bootstrap

Basically, the paths are not hardcoded, and can be configured whenever and however you want; you just need to know where and when to configure them.

Posted by matthew ishii (mishii1776) on 2010-03-30T11:05:57.000+0000

Matthew - Very sorry, I had done a grep on the source and had seen 'views' in quotations - I made a risky assumption that this meant it was not configurable or changed later if configured differently.

Thank you for showing me how this is possible - again I apologize.

Posted by Matthew Weier O'Phinney (matthew) on 2010-03-30T14:22:29.000+0000

No worries -- just wanted to point out where and how to configure. :)

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.