2010-03-15 23 views
2

「意見」通常情況下它會在這樣的結構:如何移動的Zend_Layout的

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

如何我將它移動到:

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

回答

3

你需要玩:在frontController插件,$viewRenderer::setViewBasePathSpec();

例如(或更容易,但沒有那麼靈活,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/"); 

採取的getter和setter看看在frontControllerview,layoutviewRenderer類。有很多方法可以自定義默認的目錄結構。

0

我用插件做了它,並在我的配置中設置了一個變量來指定主題的名稱。

class Application_Plugin_ThemeSetup extends Zend_Controller_Plugin_Abstract 
{ 
    public function preDispatch(Zend_Controller_Request_Abstract $request) 
    { 
     // load up the config and the view object 
     $objConfig = Zend_Registry::get('config'); 
     $objView = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'); 

     // set path for views based on theme designation in config 
     $theme = ! empty($objConfig->theme->name) ? $objConfig->theme->name : 'default'; 

     $Renderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); 
     $Renderer->setViewBasePathSpec(APPLICATION_PATH."/views/$theme"); 

     // add some variable to the view at high level 
     $objView->themeName = $objConfig->theme->name; 
     $objView->themeDescription = $objConfig->theme->description; 
    } 
}