Yii Framework Forum: beforeRender and afterRender - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • This topic is locked

beforeRender and afterRender

#21 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 601
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 29 January 2013 - 03:06 PM

Dear Experts

I like the afterRender method, since parameter $output(the content rendered) is passed as referrence.

Inside this method,We can modify the content rendered.

seeni.
0

#22 User is offline   clapas 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 21-February 11

Posted 01 April 2013 - 01:08 PM

I raise the afterRender event in my controllers so an attached behavior can subscribe to the event and output view content or register CSS or Javascript code.

I wouldn't be able to do that by using the beforeAction or afterAction events. Would I?
0

#23 User is offline   rAWTAZ 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 08-January 10

Posted 01 April 2013 - 01:23 PM

@clapas You can probably start output buffering in beforeAction and fetch it in afterAction and thereby process the output, but it's hackier than having the beforeRender/afterRender ones where you get the output.

There's also a difference; There might be actions that doesn't render things in the common way and in these cases you might not want your beforeAction/afterAction to apply, hence being able to use beforeRender/afterRender in these cases might be good.

I'm thinking there are enough use cases to preserve these events after all.
0

#24 User is offline   clapas 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 21-February 11

Posted 03 April 2013 - 05:52 AM

View PostrAWTAZ, on 01 April 2013 - 01:23 PM, said:

@clapas You can probably start output buffering in beforeAction and fetch it in afterAction and thereby process the output, but it's hackier than having the beforeRender/afterRender ones where you get the output.

I wonder if buffering output could interfere with nested output buffering, e.g. I think Yii clips use output buffering. May be more Yii methods use output buffering during the render phase, not sure...

View PostrAWTAZ, on 01 April 2013 - 01:23 PM, said:

There's also a difference; There might be actions that doesn't render things in the common way and in these cases you might not want your beforeAction/afterAction to apply

Sorry, I don't understand what you mean here. Could you explain please?
0

#25 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,124
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 15 April 2013 - 03:48 AM

In this post, zaccaria explains one of reasons for using afterRender().

I was thinking about using beforeRender or afterRender to insert some extra content to larger group of my views (not all of them, but a significant number, among different controllers). But this path turned out to be wrong. I think behaviors will be better.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • This topic is locked

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