Yii Framework Forum: Manipulate Dom Of View Before Being Rendered - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Manipulate Dom Of View Before Being Rendered Rate Topic: -----

#1 User is offline   epferreira 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-November 13

Posted 22 November 2013 - 06:40 AM

Hello

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
0

#2 User is offline   epferreira 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-November 13

Posted 22 November 2013 - 08:14 PM

Hello

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.

Regards
0

#3 User is offline   guaruja 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 10-March 12

Posted 23 November 2013 - 07:34 AM

View Postepferreira, on 22 November 2013 - 08:14 PM, said:

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.


Did you try renderPartial() ?
0

#4 User is offline   epferreira 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-November 13

Posted 26 November 2013 - 12:00 PM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users