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 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法