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.

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失