Yii Framework Forum: Action Filter vs. Behavior - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Action Filter vs. Behavior

#1 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,752
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 May 2012 - 10:21 AM

For 2.0, I am thinking to remove action filters in favor of behaviors. As you know, behaviors can respond to events of their owners. Using this mechanism, it is possible to make a behavior to work like a filter.

Of course, there are still some differences between filters and behaviors. Below are the ones that are not easy or straightforward enough to implement filters using behaviors:
  • Filters' before and after methods are properly nested.
  • If an inner filter's before method quits, the outer filters' after methods still get chance to be executed.


Your opinion is welcome!
0

#2 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 645
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 03 May 2012 - 10:33 AM

I was a bit worried that with the new event system (which is great) the filtering features upon certain events would be completely removed. I'm glad to see this.

I'm ok with having behaviors instead of action filters.
Rodrigo Coelho


Check my extension
giix: a code generator for Yii. Posted Image


The complete beginner's study guide for the Yii Framework
0

#3 User is offline   Junior - df9 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 407
  • Joined: 24-May 09
  • Location:Brazil

Posted 03 May 2012 - 10:35 AM

Hi, Qiang!

Could you please explain or provide more details about what are the intended benefits of removing the feature? Think that it would help ppl giving feedback. (like improve performance, simplify app flow..)

Thanks
______________________________________
Junior
df9.com.br
Linux Registered User #364954
GNU/Linux: together we're ready!
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,752
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 May 2012 - 11:13 AM

My main consideration is to simplify the concepts, removing things that are unnecessary or redundant.

While filters are useful, they should not be limited to actions only. Theoretically, filters can be used in the whole request workflow. With events and behaviors, we can achieve this goal already.
0

#5 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 2,648
  • Joined: 17-January 09
  • Location:Russia

Posted 03 May 2012 - 11:15 AM

How would an access control behavior look now?
0

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,752
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 May 2012 - 01:28 PM

It will be similar to CAccessControlFilter, except that it needs to attach to the 'authorize' event of controller in its init() function.
The controller action work flow will consist of these events: authorize, beforeAction, beforeRender, afterRender, afterAction
2

#7 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 2,648
  • Joined: 17-January 09
  • Location:Russia

Posted 03 May 2012 - 02:29 PM

Sounds good.
0

#8 User is offline   yJeroen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 06-September 11
  • Location:The Netherlands

Posted 03 June 2012 - 03:53 PM

View Postqiang, on 03 May 2012 - 01:28 PM, said:

It will be similar to CAccessControlFilter, except that it needs to attach to the 'authorize' event of controller in its init() function.
The controller action work flow will consist of these events: authorize, beforeAction, beforeRender, afterRender, afterAction

Question: Will you use ouput buffer to force the right order of beforeRender <output> afterRender? That way the events are even triggered if you use echo in the controller action.

Or will these two events only be implemented in the CController::render(), like it is now?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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