duan2428 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?

  • 写回答

1条回答 默认 最新

  • dongqi0644 2013-07-22 10:56
    关注

    The answer is no. First of all, you have already figured out that the file name is private in Zend\View\Renderer\PhpRenderer. Second, it well could be something completely different, for instance ZfcTwig\View\Resolver\TwigResolver, which does not have such a property.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?