Help handling subdomains and dynamic loading app content and themes

Hi there,

I got some doubt on how to perfectly configure and setup a service using Yii and subdomains. Here follows the problem:

I want to be able to provide the service to my clients so that they can run their own istance of the service thourgh Connecting to this domain the app should load the specific customer’s instance of the service (content and theme).

On my dbschema the customer is modeled as and entity with all his related content. So suppose that each customer can provide some articles running on a customized layout, how I should find a way to have all this working? Can I do it all just using the urlManager?

In this case I cant understand how to make it working cause I should retrieve the customer instance from DB before resolving the url to have something like

 '' => 'customer/custId/articles/index',

Or maybe I could put the customerId as a GET parameter on every entry

 '' => 'site/index?custId=N',

         '' => 'customer/articles/index?custId=N',

         '' => 'customer/photos/index?custId=N',

And putting some sort of check con CController I can set it someting like

Yii::app()->params['custId'] = N

so that later on I can use it all over the app.

Anyway all this looks more like workaround than like a real solution. Any help would be very appreciated.

Best Regards


I’m sure someone will come over the top of me with a more elegant solution, but I’ll lend my 2 cents. From the sound of things, each URL should resolve to the same action & controller, is that correct?

i.e. and will both resolve to the articles controller.

The urlManager should handle that out of the box. All that remains is retrieving the customer id from the subdomain and making that information available to your controller (so it knows what articles to pull), in which case you could simply just extend the Controller class (or edit it).

i.e. create a public $customer data value in your base Controller class and create an init() function which queries your database for the customer details (and sets the theme/layout if need be).

HI Artificial,

you perfectly got the problem and as a quick and dirty solution this should fit pretty fine, parametrizing the subdomain part with urlManager should handle all the dirty work :)

I’ll let you know the final solution