phpzend-frameworkzend-layout

How to move the "views" of Zend_Layout


Normally it would be in such a structure:

../application/modules/somemodule/views/scripts/index/index.phtml

How I move it to:

../application/templates/somemodule/template1/views/......
../application/templates/somemodule/templateTWOOMG/.......

??


Solution

  • You need to play with: $viewRenderer::setViewBasePathSpec();

    For example in frontController plugin, (or easier, but not so flexible, in Bootstrap.php):

    $templateName = 'myTemplate';
    
    $bootstrap = $this->getBootstrap();
    
    $bootstrap->bootstrap('layout');
    if ($bootstrap->hasResource('layout')) {
        $layout = $bootstrap->getResource('layout');
        $layout->setLayoutPath($basePath . '/layouts/scripts/');
    }
    
    $bootstrap->bootstrap('view');
    if ($bootstrap->hasResource('view')) {
        $view = $bootstrap->getResource('view');
    } else {
        $view = new Zend_View;
    }
    
    $vr = Zend_Controller_Action_HelperBroker::getExistingHelper("viewRenderer");
    $vr->setViewBasePathSpec($basePath."/modules/:module/$templateName/views/");
    

    Take a look on getters and setters in frontController, view, layout and viewRenderer classes. There are plenty of methods which allow to customize default directory structure.