2

How is it possible to set up a shared view script path for partials to create global partials within the Zend Framework?

We know that you can call partials between modules

e.g  -  echo        $this->partial('partial_title','module_name');

but we need to set up a partial folder in the root ( i.e below modules) so that it can be accessble by all views.

It has been suggested to set up a shared view script path, how is this done?

4

2 回答 2

11

Zend_View有一个名为 的方法addScriptPath,因此在Zend_Controller_Action子类中您可以执行以下操作:

$this->view->addScriptPath("/path/to/your/view/scripts/");

现在,当您调用renderorpartial或时partialLoop,该路径将包含在路径中。

于 2009-12-02T16:18:55.620 回答
0

我有一个解决方案。我们可以通过指定视图的位置来做到这一点:

像上面那样调用部分表单模块/控制器页面

方法一:

$this->view->addScriptPath("/ModuleConatinerDirectory/ModuleName/view/scripts/");

然后使用加载:

$message = $this->view->partial('templates/default.phtml','contact',array('var'=> 'var');

对于第二个选项,请阅读以下内容:

http://framework.zend.com/issues/browse/ZF-6201

现在我的疑问是,是否可以直接在我的所有模块的引导文件上设置它?如果是这样,我该如何为两个模块 Module1 和 Module2 设置这个

$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $viewRenderer->setViewBasePathSpec('/some/absolute/path/to/templates/:module/');

于 2010-03-03T14:09:37.450 回答