Manipulate Dom Of View Before Being Rendered


Is it possible to do this?

I’d like to manipulate the DOM included in the view using a server side library (PHP Simple HTML DOM Parser for instance) but I do not know how to manipulate (server side) the DOM of a view before being output to the browser.

I’ve tried the PHP Output Buffer functions but it seems that Yii uses it extensively and when I try to use ob_start() Yii must have other ob_start in the code that is flushed and printed to the browser and does the same with mine.

Thank you


I’ve found a way to do it. The render method allows to pass an argument that allows to override the default echo of the view output and store it on a variable that can be manipulated.

The only downside is that every rendered view includes in its output the layout rendering as well, so I have to find way of not wasting resources by parsing the layout in every view that is output to the presentation layer.

I have to think a bit about it and if, or when :), I find an acceptable way(performance wise) of doing it, I’ll post it here.


Did you try renderPartial() ?

Yes that would be a way to do it if I hadn’t express myself incorrectly… I’m sorry

My concern was related to having to invoke the parse methods on DOM layout in every action method.

I solved it by adding those methods invokation on methods of the Controller class that I’ve prepared to return the DOM that I wish to parse.

Being so, my problem is solved. Thanks for the hint, and again, sorry about the misleading observation