Zend Framework 2-如何包括库中的部分库 [英] Zend Framework 2 - How to include partial from library
问题描述
我写了一部分,希望在几个模块中使用.我认为最好的方法是将其放入我的自定义库中.
I wrote a partial which I want to use in several modules. I thought the best way would be to put it into my custom library.
但是不幸的是,如果不使用类似以下这样的丑陋路径,我将无法找到一种包括该部分内容的方法:
But unfortunately I couldn't figure out a way to include this partial without using a very ugly path like:
echo $this->partial('/../../../../vendor/myvendor/library/MyVendor/View/Views/FormPartial.phtml'
, array(...));
有什么想法可以从我的角度链接到我的供应商目录吗?
Any ideas how to link to my vendor directory from my view?
推荐答案
问题是解析器无法解析您提供的视图模板的路径.我通常会在module.config.php
The problem is the resolver can't resolve the path of the view template you had provided. I usually add a configuration entry for all accessible partials in the template_map entry in the module.config.php
例如 我的view/layout/header.phtml和view/layout/footer.phtml
for example I have header and footer partials like this my view/layout/header.phtml and view/layout/footer.phtml
下面是我的配置
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'header' => __DIR__ . '/../view/layout/header.phtml',
'footer' => __DIR__ . '/../view/layout/footer.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
在我的布局视图脚本中,我简单地放入了
and inside my layout view script I simply put
<?php echo $this->partial('header'); ?>
和
<?php echo $this->partial('footer'); ?>
如果您的部分代码采用/module/controller/action格式,那么您也可以这样做
Another if you have your partials under /module/controller/action format you can also do
<?php echo $this->partial('/module/controller/action'); ?>
您应将视图脚本放置在模块控制器文件夹的视图文件夹中
you should place the view script in the view folder of your module's controller folder
这篇关于Zend Framework 2-如何包括库中的部分库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!