Yii Framework Forum: Different Database For Different Countries - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Different Database For Different Countries Rate Topic: -----

#1 User is offline   darioo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 76
  • Joined: 10-July 13

Posted 23 October 2013 - 05:03 AM

I wanted to buy 3 different domains in 3 different countries. I wanted to show the same website on all 3 domains but with different content and users. Is there any possibility so that I can somehow use the same yii site but just read from different database depending which domain is currently in use?

Another problem is that I will be using cronjobs to modify data in database depending on country.
0

#2 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 685
  • Joined: 12-September 10
  • Location:Austria

Posted 23 October 2013 - 07:43 AM

You can load different config files, depending on $_SERVER['HTTP_HOST'] in the index.php.

switch($_SERVER['HTTP_HOST'])
{
    case 'domain1.com':
       $config = 'main_domain1.php';
       break;
    case 'domain2.com':
       $config = 'main_domain2.php'
       break;
   ....
    default:
        $config = 'main.php'
}

....
Yii::createWebApplication($config)->run();



Or merge a main.php without a db component config with different config files containing the db settings only.


switch($_SERVER['HTTP_HOST'])
{
    case 'domain1.com':
       $dbConfig = 'db1.php';
       break;
    case 'domain2.com':
       $dbConfig = 'db2.php';
       break;
   ....
    default:
        $dbConfig = 'db.php';
}


require('path/to/yii.php');

$dbCfg=require('path/to/'.$dbConfig);
$base=require('path/to/main.php');

$config=CMap::mergeArray($base, $dbCfg);

Yii::createApplication($config)->run();



See: Section Application Configurations

http://www.yiiframew...ii-project-site
1

#3 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 153
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 23 October 2013 - 07:44 AM

View Postdarioo, on 23 October 2013 - 05:03 AM, said:

I wanted to buy 3 different domains in 3 different countries. I wanted to show the same website on all 3 domains but with different content and users. Is there any possibility so that I can somehow use the same yii site but just read from different database depending which domain is currently in use?

Another problem is that I will be using cronjobs to modify data in database depending on country.



This wiki would help you..

http://www.yiiframew...ultiple-domains
2

#4 User is offline   darioo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 76
  • Joined: 10-July 13

Posted 23 October 2013 - 12:01 PM

great solutions. thanks :D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users