Dessert #5 - Keep a custom configuration file
Posted by Felix Geisendörfer, on Sep 16, 2006 - in PHP & CakePHP » Core & Hacking
Deprecated post
The authors of this post have marked it as deprecated. This means the information displayed is most likely outdated, inaccurate, boring or a combination of all three.
Policy: We never delete deprecated posts, but they are not listed in our categories or show up in the search anymore.
Comments: You can continue to leave comments on this post, but please consult Google or our search first if you want to get an answer ; ).
One thing that I found pretty useful when developing CakePHP applications, is to put an additional configuration file with definitions and settings specific to the current project into the /app/config folder. So for example when working on an application called lugsteinhof, I would put this into my bootstrap.php:
Then I would create a file in /app/config/ called lugsteinhof.php and fill it with information like this:
-
-
/**
-
* Figure out whether the script is running on the local development machine, or
-
* in an production enviornment. You can also manually define this value above
-
* in which case the code below won't get executed
-
*/
-
{
-
else
-
}
-
-
/**
-
* The default theme if none is available via database
-
*/
-
-
// More definitions and settings ...
Oh and if you are curious about the SERVER_ENVIORNMENT definition, I use it to automatically switch between development & production database configuration. To do this I simply modified my /app/config/database.php like this:
-
class DATABASE_CONFIG
-
{
-
var $default = null;
-
-
'connect' => 'mysql_connect',
-
'host' => 'localhost',
-
'login' => 'production-user',
-
'password' => 'production-pw',
-
'database' => 'lugsteinhof',
-
'prefix' => '');
-
-
'connect' => 'mysql_connect',
-
'host' => 'localhost',
-
'login' => 'dev-user',
-
'password' => 'dev-pw',
-
'database' => 'dev-lugsteinhof',
-
'prefix' => '');
-
-
function DATABASE_CONFIG()
-
{
-
$this->default = $this->{SERVER_ENVIRONMENT};
-
}
-
}
Btw., I took the idea of automatically checking whether the code is running on my dev machine or in production enviornment from Jonathan Snook's post called Ease Deployment with Automatic Server Check.
--Felix Geisendörfer aka the_undefined