Zend Framework - 渲染布局之前执行的最后一个代码

发布于 2024-08-21 11:59:57 字数 662 浏览 13 评论 0原文

我想在执行所有其他代码之后,在渲染布局之前执行一些代码。我该把代码放在哪里?

我特别尝试在布局使用 headLink、headScript 和 inlineScript 视图助手中引用的文件之前对其进行修改。

以下是我要采取的步骤:

  1. 循环这些视图助手中的文件
  2. 制作本地文件列表
  3. 从视图助手中删除本地文件
  4. 将本地文件列表作为参数引用到将它们组合为单个 HTTP 的服务器脚本请求
  5. 将新的组合脚本引用添加到适当的视图助手

前端控制器插件似乎不会帮助我完成此任务,原因如下:

  1. postDispatch() 在每个控制器操作后执行已执行,我需要样式表/javascript 的完整列表
  2. 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:

  1. Loop over the files in those view helpers
  2. Make a list of the local files
  3. Remove local files from the view helpers
  4. Reference the local file list as a parameter to a server script that combines them for a single HTTP request
  5. 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:

  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

As Rufinus suggested, I solved this by extending the View Helpers. My question from that angle as well as the solution is here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戈亓 2024-08-28 11:59:57

ZF1 调度流程概述 (c) 作者:Thorsten Ruf

请参阅 由 Thorsten Ruf 创建的原始 PDF
镜像

您可以通过插件访问的最后一部分应该是调度循环关闭

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

ZF1 Dispatch Process Overview (c) by Thorsten Ruf

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文