Zend Framework-渲染布局前要执行的最后代码 [英] Zend Framework - Last Code to Execute Before Layout is Rendered

查看:95
本文介绍了Zend Framework-渲染布局前要执行的最后代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在所有其他代码执行完后立即在呈现布局之前执行一些代码.我将把代码放在哪里?

I want to execute some code right before the layout is rendered, after all other code is executed. Where would I put that code?

我专门在修改布局使用的headLink,headScript和inlineScript视图帮助器中引用的文件之前.

I am specifically trying to modify the files referenced in the headLink, headScript, and inlineScript view helpers before they're used by the layout.

这是我要采取的步骤:

  1. 查看这些视图帮助器中的文件
  2. 列出本地文件
  3. 从视图助手中删除本地文件
  4. 将本地文件列表作为服务器脚本的参数引用,该服务器脚本将它们组合成一个HTTP请求
  5. 将新的合并脚本引用添加到适当的视图助手中


似乎没有Front Controller插件可以帮助我完成此任务,这就是原因:


It doesn't appear that a Front Controller Plugin is going to help me accomplish this, and here's why:

  1. postDispatch()在执行完每个控制器动作后执行,我需要样式表/javascript的完整列表
  2. dispatchLoopShutdown()在控制器动作循环后执行,但此时布局已呈现
  1. postDispatch() gets executed after every controller action that's executed, and I need the full list of stylesheets/javascripts
  2. dispatchLoopShutdown() gets executed after the controller action loop, but the layout has already been rendered at this point


正如Rufinus所建议的,我通过扩展View Helpers来解决了这个问题. 我从这个角度出发的问题以及解决方案都在这里

推荐答案

请参见由Thorsten Ruf创建的原始PDF (镜像)

您可以通过插件访问的最后一部分应该是dispatchLoopShutdown

the very last part you can access via plugin should be dispatchLoopShutdown

对于ZendFramework2,请参见 http://zendframework2.de/en/cheat-sheet.html 此gdoc

For ZendFramework2 see http://zendframework2.de/en/cheat-sheet.html or this gdoc

这篇关于Zend Framework-渲染布局前要执行的最后代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆