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.
beforeRender and afterRender
#22
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?
I wouldn't be able to do that by using the beforeAction or afterAction events. Would I?
#23
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.
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.
#24
Posted 03 April 2013 - 05:52 AM
rAWTAZ, 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...
rAWTAZ, 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?
#25
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.
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!

Help
This topic is locked











