如何移动Zend_Layout的“视图”

时间:2010-03-15 21:07:50

标签: php zend-framework zend-layout

通常它会是这样的结构:

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

我如何将其移至:

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

...

2 个答案:

答案 0 :(得分:3)

您需要使用:$viewRenderer::setViewBasePathSpec();

例如在frontController插件中,(或更简单,但不是那么灵活,在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/");

frontControllerviewlayoutviewRenderer课程中查看getter和setter。有很多方法可以自定义默认目录结构。

答案 1 :(得分: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;
    }
}