2013-07-22 09:10
浏览 43

ZF2 - 在自定义视图助手中获取当前视图模板的路径

In Zend Framework 2, I am trying to get the path of the current view template in a custom view helper.

If I have a view helper called "testThis" and I am rendering a template located at view/inside/bar/baz.phtml then I want to be able to get this path from within the "testThis" __invoke method.

This should always get the calling view though - for example if inside this baz.phtml file I use the partial helper to load another template called boo.phtml, then if I called "testThis" from within this boo.phtml template I would get that path instead of the baz.phtml.

Is this possible and if so, how to do it?

Edit: If I add a function to Zend\View\Renderer\PhpRenderer that returns the private variable $__template then I get exactly what I need but it would be nice to not have to modify the framework - is there a way to get it without adding this function?

图片转代码服务由CSDN问答提供 功能建议

在Zend Framework 2中,我试图在自定义视图助手中获取当前视图模板的路径。 / p>

如果我有一个名为“testThis”的视图助手,我正在渲染位于view / inside / bar / baz.phtml的模板,那么我希望能够从 “testThis”__invoke方法。

这应该总是得到调用视图 - 例如,如果在这个baz.phtml文件中我使用部分帮助器加载另一个名为boo.phtml的模板,那么 如果我从这个boo.phtml模板中调用“testThis”,我会得到那条路径而不是baz.phtml。


编辑:如果我向Zend \ View \ Renderer \ PhpRenderer添加一个返回私有变量$ __ template的函数,那么我得到了我需要的东西,但不必修改框架会很好 - 有没有办法在不添加此功能的情况下获得它?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题