We are building our Yii app (in the cloud) and have several customers that are going to use this application. They all have their own domain (example: app.company.com, app.anothercompany.com, etc.). We would like to load a different configuration file per domain so we can use a different database connection per domain, a different theme map, etc. We would like to load the config files files from a central place that will be easily to manage.
What would be the best approach in doing this? Any opinions?
Samdark wrote an article about this on his blog. Although my russian skills suck it is easy to get the idea. You simply place a condition in your index.php to load the right config array according to the host
This example loads a config defined in dev.php if the host is localhost, else it is using production.php which it is then merging with the main.php (where you put all the general config stuff into that is used by all domains)
Thanks guys… decided to place the configs in a separate part on our servers and to include based on the domain name. That way we don’t have to create many switch/case statements but just include the ‘/environments/{current-hostname}/config.php’ file.
If there is not a config file for the ‘current’ hostname we will redirect the user to our company website.
Very nice to get good/quick answers in this community! Tnx.
Thank you! This is exactly what I was looking for.
If only I’ve read your post earlier. I’ve just spent a while by making the custom function that does exactly the same as CMap::mergeArray. It’s amazing how many useful components Yii has.