Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

php - Zend Framework - Last Code to Execute Before Layout is Rendered

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...