問題描述
我想在渲染布局之前執行一些代碼,然后執行所有其他代碼.我會把那個代碼放在哪里?
我特別想在布局使用 headLink、headScript 和 inlineScript 視圖助手中引用的文件之前對其進行修改.
以下是我要采取的步驟:
- 循環那些視圖助手中的文件
- 列出本地文件
- 從視圖助手中刪除本地文件
- 將本地文件列表作為參數引用到服務器腳本,該腳本將它們組合起來用于單個 HTTP 請求
- 將新的組合腳本引用添加到適當的視圖助手
<小時>
前端控制器插件似乎不會幫助我實現這一點,原因如下:
postDispatch()
在執行每個控制器操作后執行,我需要樣式表/javascripts 的完整列表dispatchLoopShutdown()
在控制器動作循環后執行,但此時布局已經呈現
<小時>
正如 Rufinus 所建議的,我通過擴展視圖助手解決了這個問題.(鏡像)
您可以通過插件訪問的最后一部分應該是 dispatchLoopShutdown
ZendFramework2 參見 http://zendframework2.de/en/cheat-sheet.html或 這個 gdoc
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.
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
這篇關于Zend 框架 - 在呈現布局之前執行的最后一段代碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!