I have a filter setup that runs a function which checks if the user session is present on certain actions, like so;
<cffunction name="init">
<cfset filters(through="checkLogin", except="login,register,signin,create,home,profile") />
</cffunction>
The problem is, these are the action names…which conflict from other controllers I have.
For example, I have 2 controllers ‘user’ and ‘link’. Each of these has an action called create, so that my URL’s are like so:
/user/create/
/link/create/
How can the filter know with which controller to associate it with? Is there a way to prefix certain ‘actions’ in the ‘except’ clause with the controller name too?
For example, maybe something like:
<cffunction name="init">
<cfset filters(through="checkLogin", except="user/login,user/register,user/signin,link/create,main/home,user/profile") />
</cffunction>
I remember trying this but it didn’t work and borked.
Hope you understand what I’m saying here. I don’t want to have to name every action in separate controllers totally unique names.
Thanks,
Michael.
You can use basic inheritance to accomplish this:
Then in any child controller (
user, for example), you can specify which actions to exclude. This works well because the parent controller should really know nothing about its children. It implements what it cares about and nothing else.If another child always wants for
checkLoginto run, then it shouldn’t pass a value forcheckLoginExcept: