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

Description

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.

Comments

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');
$vr->setViewBasePathSpec(':moduleDir/view');
  • 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.

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.

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