Zend Framework - 渲染布局之前执行的最后一个代码
我想在执行所有其他代码之后,在渲染布局之前执行一些代码。我该把代码放在哪里?
我特别尝试在布局使用 headLink、headScript 和 inlineScript 视图助手中引用的文件之前对其进行修改。
以下是我要采取的步骤:
- 循环这些视图助手中的文件
- 制作本地文件列表
- 从视图助手中删除本地文件
- 将本地文件列表作为参数引用到将它们组合为单个 HTTP 的服务器脚本请求
- 将新的组合脚本引用添加到适当的视图助手
前端控制器插件似乎不会帮助我完成此任务,原因如下:
postDispatch()
在每个控制器操作后执行已执行,我需要样式表/javascript 的完整列表dispatchLoopShutdown()
在控制器操作循环之后执行,但此时布局已经渲染
正如 Rufinus 所建议的,我通过扩展解决了这个问题视图助手。 我从这个角度提出的问题以及解决方案在这里 。
I want to execute some code right before the layout is rendered, after all other code is executed. Where would I put that code?
I am specifically trying to modify the files referenced in the headLink, headScript, and inlineScript view helpers before they're used by the layout.
Here are the steps I want to take:
- Loop over the files in those view helpers
- Make a list of the local files
- Remove local files from the view helpers
- Reference the local file list as a parameter to a server script that combines them for a single HTTP request
- Add that new combine script reference to the appropriate view helper
It doesn't appear that a Front Controller Plugin is going to help me accomplish this, and here's why:
postDispatch()
gets executed after every controller action that's executed, and I need the full list of stylesheets/javascriptsdispatchLoopShutdown()
gets executed after the controller action loop, but the layout has already been rendered at this point
As Rufinus suggested, I solved this by extending the View Helpers. My question from that angle as well as the solution is here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 由 Thorsten Ruf 创建的原始 PDF
(镜像)
您可以通过插件访问的最后一部分应该是调度循环关闭
编辑:
对于 ZendFramework2,请参阅 http://zendframework2.de/en/cheat-sheet.html
或此 gdoc
see Orginal PDF created by Thorsten Ruf
(Mirror)
the very last part you can access via plugin should be dispatchLoopShutdown
EDIT:
For ZendFramework2 see http://zendframework2.de/en/cheat-sheet.html
or this gdoc