我写了一个我想在几个模块中使用的部分。我认为最好的方法是将它放入我的自定义库中。
但不幸的是,如果不使用非常丑陋的路径,我想不出一种方法来包含这个部分:
echo $this->partial('/../../../../vendor/myvendor/library/MyVendor/View/Views/FormPartial.phtml'
, array(...));
任何想法如何从我的视图链接到我的供应商目录?
我写了一个我想在几个模块中使用的部分。我认为最好的方法是将它放入我的自定义库中。
但不幸的是,如果不使用非常丑陋的路径,我想不出一种方法来包含这个部分:
echo $this->partial('/../../../../vendor/myvendor/library/MyVendor/View/Views/FormPartial.phtml'
, array(...));
任何想法如何从我的视图链接到我的供应商目录?
问题是解析器无法解析您提供的视图模板的路径。我通常在 module.config.php的template_map条目中为所有可访问的部分添加一个配置条目
例如,我有这样的页眉和页脚部分我的 view/layout/header.phtml 和 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',
),
在我的布局视图脚本中,我简单地放了
<?php echo $this->partial('header'); ?>
和
<?php echo $this->partial('footer'); ?>
另一个如果你在 /module/controller/action 格式下有你的部分,你也可以这样做
<?php echo $this->partial('/module/controller/action'); ?>
您应该将视图脚本放在模块控制器文件夹的视图文件夹中