clone application, different DB only

What i really want:

i have one application (advanced template) with frontend/backend. now i need this for two languages (on different domains / web root, same server) and with different content.

i thought the easiest way is to somehow clone the application and run the copy with a different database connection - without having to copy all views and controllers and changing namespace. i need to have only one codebase to change for both languages.

if i knew before, i would have used modules.

can this be done? if yes, how?

answering my own question:

  1. first i moved all /backend/controllers into /common/backend/controllers and changed namespaces

  2. i moved all /backend/views into /common/backend/views

  3. in backend/config/main.php i added controllerNamespace and components[‘view’] to wire things up


    'controllerNamespace' => 'common\backend\controllers',

    'components'          => [

        'view' => [

            'theme' => [

                'pathMap' => [ 

                    '@backend/views' => [ 






same for frontend. didn’t have to change links anywhere!

hope this helps anybody else!

Yes this is a way… but for me this is a wrong use of the common concept

Common is a sharing area for common code to different application.

For instance you use common to share models between front end backend and api, share some of the views between back and front an so on.

In you case you have exactly the same application but what change is the database. You can reach this in several ways, 2 that came quickli to my mind are:

[list=1][]switch the connection based on the client request (best one since you get 2 different database)[]change table prefix based on the client request (useful if you can’t have 2 different database)[/list]A code snippet, ie modify common/config/main-local.php

switch ($_SERVER[ 'SERVER_NAME']) {

 	case 'site_1':






 	case 'site_2':






 		die('the application your requsted does not exist');


return [

	'components' => [

    	'db' => [

        	'class' => 'yii\db\Connection',

        	'dsn' => "mysql:host=$host;dbname=$dbName",

        	'username' => $user,

        	'password' => $password,

        	'charset' => 'utf8',


With your way when you will need to create an application (front or api) which really share only part of the code you already developed you will be in trouble.

thank you for your great input! as it showed out, my copy&paste proved to be more useful, only because i had way too many variations in my views (more than i expected).

for my next project i plan to use your approach and place the customization in the db.