Question

I am using yii to develop an application. I want to have 1 codebase on the server and have that code point to a differet database depending if im in a sub domain. All databases will be identical.

I have a few pages that are on my main site; eg. www.test.com, which point to the main databse, and when the user logs in, point them over to the subdomain, now with the new connection string so the code works as normal for them.

Could someone help me out as to what I need to do to accomplish this please. I have a textbox on the login screen that says "enter your keyword", so it could be boat for example and the code would end up shooting them to "boat.test.com". And then from there how do I make it work with some specific files for that client?

Any help would be appreciated!! Thanks in advance

Was it helpful?

Solution

If you use a LAMP stack, you can set this up fairly easily. Here's how:

  1. Move the application out of your document root.
  2. Create multiple document roots, one for each domain.
  3. Each document root should have symbolic links to any assets directories, or anything else that is accessible from the domain that needs to be the same. Maybe assets, and js. css and images may need to be local if each domain needs a different look and feel.
  4. Set up a different virtual host for each domain.
  5. your index.php needs to be different for each domain to give each domain it's own configuration file.
  6. Create a separate configuration file for each domain which will allow you to provide localized database configuration information.
  7. You can merge the localized configuration with a common configuration so that you don't have to duplicate the entire main.php.

Under Windows you can do the same thing, but everything that remains in your document root needs to be duplicated once you move the application out of document root.

Here is an interesting page to read: http://www.yiiframework.com/wiki/116/moving-project-code-outside-of-webroot-plus-multiple-project-support/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top