代码之家  ›  专栏  ›  技术社区  ›  Mark

动态设置视图目录

  •  0
  • Mark  · 技术社区  · 17 年前

    现在,我的视图目录结构如下所示:

    /application/views/scripts/brand1/
    /application/views/scripts/brand1/index/index.phtml
    /application/views/scripts/brand1/error/error.phtml
    /application/views/scripts/brand2/
    /application/views/scripts/brand2/index/index.phtml
    /application/views/scripts/brand2/error/error.phtml
    /application/views/scripts/brand3/
    /application/views/scripts/brand3/index/index.phtml
    /application/views/scripts/brand3/error/error.phtml
    and so on.
    

    我在bootstrap.php中使用addScriptPath()函数,如下所示

    protected function _initView()
    {
        $view = new Zend_View();
        $view->doctype('XHTML1_STRICT');
        $view->env = APPLICATION_ENV;
        $view->addScriptPath(APPLICATION_PATH . '/views/scripts/brand1');
        $view->addHelperPath(APPLICATION_PATH . '/views/helpers');
    
        ...
    }
    

    但是,当运行此程序时,它将使用/views/scripts/brand1/(action).phtml查找所有视图,而不是使用正确的方案/view/scripts/brand1/(controller)/(action).phtml查找视图

    1 回复  |  直到 17 年前
        1
  •  1
  •   Mark    17 年前

    我知道我在这里发布后会找到答案。如果其他人遇到同样的问题,解决方案是:

    $view->setBasePath(APPLICATION_PATH . '/views/brand1');
    

    然后将目录结构修改为:

    /application/views/brand1/scripts/...