Currently I am using "partials" concept in my FW/1 views: these chunks of layout that can be re-used by different views. They are prefixed with underscore for easier maintenance, but unlike the CFWheels these still can be used as implicit views which is not very good.
For example, there's a directory structure:
/views/member/_user.cfm
/views/member/profile.cfm
/views/member/register.cfm
This way actual user form is in the _user.cfm and can be included to the two others using #view('member/_user')#
.
What I want is to prevent access to the pages like member._user
on the website.
One solution is to create the _user
method in member.cfc
controller and redirect user somewhere. But creating such methods for each partial is kinda inefficient approach.
Alternative to this would be parsing the rc.action
in before
and checking if there's underscore in the prefix, but I'm not sure this is clean solution.
Is it possible to disable the action (throw 404) if there's no corresponding method in controller? Or maybe there are some framework events/flags which would allow me to handle "missing method" situation in before
?
Thank you.
You can create a method in a controller that checks rc.action to see if the item part starts with a _ and redirects elsewhere (or throws an error, or whatever you want to do). Then call this method using controller() function in your setupRequest() method in Application.cfc.
For example, I have a controllers/security.cfc controller with checkItem() method as follows:
And call it in setupRequest() in Application.cfc:
This way it is automatically called on every request - no need to define a separate method for each _item in controllers.