Hello all. I have a FW/1 website with subsystem fo...
# fw1
d
Hello all. I have a FW/1 website with subsystem for salespeople. It has various sections such as sales, contacts, earnings, etc. All sections of the salesperson subsystem share a common layout that displays the salesperson header (salesperson's name, location, title and links to sections they can access). In order to display the subsection layout, I have to perform some logic in order to determine what sections the current user can access and then save rc variables used by the layout to display the salesperson header. My question is, where do I put the code for that logic? My first thought would be to put the code in the controller. But there's no 'default controller' for all sections of a subsystem. I would have to put the same lines of code in EACH controller for each section of the subsystem (sales, contacts, earnings, etc). That would seem to violate the D.R.Y. principle. My second thought was placing the code in the subsection's default layout since the code would only appear once, but that would seem to violate MVC rules of where logic should go. Where is the best place to put that code?
a
In your Application.cfc , you can run a controller (or a specific action) on the setupRequest. This will run for every request, but if the controller doesn't exist, it will be ignored. the controller (preController in this case) would be run (defaulting to default() unless otherwise specified) on every request and is subsystem specific.
Copy code
Application.cfc
...
public function setupRequest ( ) {    	
	controller(getSubSystem() & ':preController');
	...
}
...
💯 1
d
Amazing. Perfect. THANKS!
c
One other option would be to create a base subsystem controller that contains the function(s) needed to accomplish your goal here, then each of your controllers would extend that base controller and inherit the function(s).
d
@cfvonner Brilliant!