[ColdBox 3.6.0] Multiple clients (domain / enterprise) settings

I’m building an app that can be used by multiple users/organizations.

So for example

Client 1 : http://client1.mydomain.com/ or www.mydomain.com/client1
Client 2 : http://client2.mydomain.com/ or www.mydomain.com/client2
etc…

Each user can have custom settings, like a custom template. How can I swap the template based on the url of the page?

For example, client2.mydomain.com login and will have a blue template, client1.mydomain.com will have a red template.

I should create a session variable on OnRequestStart method, check the url the user is requesting and set up the right template/layout?

Personally, I would write an interceptor that checks the domain name or the incoming domain and reload configuration based on that.

The concept would be that you write a model or component that would make changes to the Application.cfc based on the URL / Domain that your looking for. Once the Application name has been changed, then each domain can be seen as a separate application sharing the code base.

I have written a few blogs that cover this over the years, as well as written this same scenario for a number of customers, so feel free to ask questions.

I have read your post: http://www.andyscott.id.au/blog/writing-a-coldbox-application-to-handle-more-than-one-site-with-orm-support

I need something similar. Could you explain how to built an interceptor that reload the configuration?

I don’t need to switch user/database, because the database is one for all users. I simply want that users can make their own personalization on template/layout.

What do you mean with “write a model or component that would make changes to the Application.cfc”? Could you give some more detailed info?

Thanks.

When making changes to the Application.cfc, it has to be done outside of ColdBox. Hence a model or component that can be called to do the work of setting up the Application.cfc for you. As you don’t need that feature, then the best option is to change the location of the views / handlers and / or layouts.

I am guessing that you handlers are all the same for each as well, so then all you need to do is use an interceptor to change the layout based on the domain name. How you do that is up to you, but the best option is creating an admin for your administrator to add the domain and the layout that you need. Just an example, you may find something else easier.

But at the end of the day, you can get the layoutLocation and change it on the request with an interceptor. But it will need to be request based as well.

psuedo code

public void function preProcess() {

var result = myLayoutService.findByDomain(“www.mydomain.com”);

controller.setSetting(‘LayoutsLocation’, result.layoutPath);

}

That should be enough to get you going.