Git ignore Yii database data

Some of the details main.phpneeded by all instances of the application (URL information) and some details will be specific to each instance of the application (database information).

Is there an idea to separate database data from protected/config/main.php?

+3
source share
3 answers

Just include the general configuration from another PHP file:

main.php:

return array
(
   ....
   'components' => array
   (
      'db' => include('sharedDatabaseConfiguration.php');
   )
);

sharedDatabaseConfiguration.php:

return array('host' => ...);

You may need to add a path or something else, depending on where the file is stored.

Edit: Btw, Yii fancy CMap:: mergeArray(), - ( , "" . console.php .

+3

: . PHP ( db) array s:

<?php
return CMap::mergeArray(
    require(dirname(__FILE__).'/db-config.php'), 
    array(
          'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
          'name' => 'Page Title',
          ...
    )
);
?>
+2

(, protected/config/production.php), , CMap::mergeArray :

return CMap::mergeArray(
    require(dirname(__FILE__) . '/main.php'),
    array(
        'components' => array(
            'db' => array(
                'connectionString' => '...',
                'username' => '...',
                'password' => '...',
            ),
        ),
    )
);

protected/config/production.php .gitignore.

+2

All Articles