Cfilter Vs. Beforeaction

I am trying to determine how/when to use class-based filters for controller actions.

My scenario is that I need to restrict access to certain controller actions based on date - our site has an open ‘window’ of membership and when today’s date is outside of that window we cannot allow signups.

I think I’ve settled on a class-based filter (since this code is common to several different controllers. I created one and overrode the preFilter() function to do what I needed - I am throwing an http exception if the date is out of range and showing a custom error explaining whats up.

Is the main difference between a Filter and a controller event (like beforeAction) that Filters can be applied per action whereas the events are for the controller as a whole?

The difference is pretty much what you mentioned yourself already: You can reuse a filter more easily for other classes.

beforeAction is local to one controller (or anything derived of course). You can also limit the beforeAction function to a specific action (it gets a CAction argument).

IMO a filter is just a more powerful and more generic way of accomplishing what you can also do with a before/afterAction.

A beforeAction is just quicker to implement and less hassle "for the smaller things"