Single codebase, multiple sites

The idea is simple: I would like to have a single codebase, but support multiple domains pointing to it, each domain configured differently (even different database).

When I say domains configured differently, I mean that these can be completely different websites, not just different themes per website. So one site can be a job listing site, another can be an article submission site, etc, all using the same "core" that handles users, auth, common components etc etc.

I have started looking into this a bit, and it’s obvious that the default way Yii works isn’t suited for this. For one thing, I would need a “websites” table in database, which stores site-specific config. But in order to read this I need the db object configured, which is also site-specific (different sites can sit on different databases).

I thought about using the themes folder but calling it "sites" instead, and using it like a theme which also includes the site-specific config, etc. Then in sites I would have "sites/", "sites/" etc, and in index.php I would need to read the site-specific config according to which domain has been accessed.

Another thing is that each site would have different controllers, actions, layouts etc, and therefore I thought of creating a SiteModule which is a type of module that pertains to a certain website "type". So I could have a jobs module for the job websites, an article module for the article websites, etc.

I am only starting to solve this problem, but I would be happy if anyone has any experience they may share, or even better, code that does something similar.

Thanks in advance!

I wrote a tutorial about it It’s in russian, but code speaks by itself.

Hi, I just have posted an enviroment class, i think it will help you if you modify some parameters, you can check it out here EASY Enviroment Class


Nice solution.

Thanks for your comment samdark! Really appreciate it! I will upload this class to the cookbok, hope help other in their projects.

nancoder, just stumbled upon your solution. Love it ! :)