1
votes

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.

1
you do know you can modfiy head* in your controller action ? e.g. $this->view->headScript()->appendFile('/js/whatever.js');Rufinus
Yes, I do, and I use that feature. I've updated my post again to be more specific.Sonny
ok now i know what you are tring to do. my best suggest is to extend the view helpers. the involved view helper using the placeholder-container view helper. by extending this classes it should be possible to do what you want. (but, to be honest, i see no big benefit in it, it would be better if you use a small weightless http daemon like lighttpd to only serve this static files.Rufinus

1 Answers

13
votes

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