Zend Framework - 共享视图脚本路径(全局部分)
如何为局部视图设置共享视图脚本路径以在 Zend 框架内创建全局局部视图?
我们知道您可以在模块之间调用部分
e.g - echo $this->partial('partial_title','module_name');
,但我们需要在根目录(即模块下方)中设置一个部分文件夹,以便所有视图都可以访问它。
有人建议设置共享视图脚本路径,这是如何完成的?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Zend_View
有一个名为addScriptPath
的方法,因此在Zend_Controller_Action
子类中,您可以执行以下操作:现在,当您调用
render
时> 或partial
或partialLoop
,该路径将包含在路径中。Zend_View
has a method calledaddScriptPath
, so in aZend_Controller_Action
subclass you could do something like:Now when you call
render
orpartial
orpartialLoop
, that path will be included in the paths.我有一个解决方案。我们可以通过指定视图的位置来做到这一点:
如上在模块/控制器页面中调用部分
方法1:
$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
现在我的疑问是,是否可以直接在我的所有模块的 Bootstrap 文件上设置它?如果是这样,我如何为两个模块 Module1 和 Module2
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper( 'viewRenderer' );
$viewRenderer->setViewBasePathSpec( '/some/absolute/path/to/templates/:module/' );
I have got a solution. We can do this by specifying the location of the view:
Calling partial as above form Module/Controller page
Method 1:
$this->view->addScriptPath("/ModuleConatinerDirectory/ModuleName/view/scripts/");
Then load using:
$message = $this->view->partial('templates/default.phtml','contact',array('var'=> 'var');
For the second option, please read the following:
http://framework.zend.com/issues/browse/ZF-6201
Now my doubt is, whether it is possible on setting it directly on Bootstrap file for all my Modules ? If so, how can I set this for two modules Module1 and Module2
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper( 'viewRenderer' );
$viewRenderer->setViewBasePathSpec( '/some/absolute/path/to/templates/:module/' );