I find myself in dire need of an onBeforeOutput event in my application.
I wrote an application component (a shopping cart) that needs to write data (current shopping cart contents) back to a cookie at the end of the request.
I hooked my application component into the CWebApplication::onEndRequest event - thinking that, at the end of the request, I would send the cart contents back as a cookie. I had not taken into account the fact that, once output has started, it’s too late to send cookies (or any other headers).
It seems like what is needed here is an event that lets you run some code at the end of the request, but before the result of the request is sent to the browser.
It occurs to me that CController::processOutput() may be an attempt to work around the same problem - the fact that certain components (such as CClientScript) need to perform some kind of post-processing, at the end of the request, before the output is sent the browser.
Perhaps it would be feasible to implement an event that CClientScript and other post-processors can hook into - providing a means for various components to set headers, send cookies, post-process the response, etc.
What do you think?