debuggable

 
Contact Us
 

Dessert #5 - Keep a custom configuration file

Posted on 16/9/06 by Felix Geisendörfer

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:

require_once(APP.'config'.DS.'lugsteinhof.php')

Then I would create a file in /app/config/ called lugsteinhof.php and fill it with information like this:

setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');

/**
 * 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
 */

if (!defined('SERVER_ENVIRONMENT'))
{
    if (strpos(env('DOCUMENT_ROOT'), 'C:/Localhost')!==false)
        define('SERVER_ENVIRONMENT', 'development');
    else
        define('SERVER_ENVIRONMENT', 'production');
}

/**
 * The default theme if none is available via database
 */

define('DEFAULT_THEME', 'summer');

// 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;
   
    var $development = array('driver'    => 'mysql',
                             'connect'  => 'mysql_connect',
                             'host'     => 'localhost',
                             'login'    => 'production-user',
                             'password' => 'production-pw',
                             'database' => 'lugsteinhof',
                             'prefix'    => '');

    var $production    =  array('driver'    => 'mysql',
                                '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

 
&nsbp;

You can skip to the end and add a comment.

[...] Andy Dawson (aka AD7six) and Felix Geisendörfer (aka the_undefined) presented in the last 24 hours solutions for switching the database configuration based on some criteria. These solutions work fine, but personally I use a different approach. [...]

Nate K said on Sep 16, 2006:

Very good tips! I actually have a few more items in a custom config file, depending on the project and its needs. Having a switch for development/production is such a timesaver - no matter what the size of the project. You can do many other things with this as well.

jacmgr  said on Jan 26, 2007:

I am curious for exampleof how you set theme using:
define('DEFAULT_THEME', 'summer');

Thankx!
John

Felix Geisendörfer said on Jan 27, 2007:

jacmgr: You mean you want to see an example for theming in CakePHP? Yeah, I think I should write about this, that's a good idea ; ).

[...] Keep a custom configuration file [...]

eregilkibly said on Dec 06, 2007:

Jungs, habt ihr eigentlich Angst vor spontaner Erektion? Text: penni-dreyer. Seite 1. Immer zum Wochenende. Jungs fragen Madchen fragen Jungs. vardenafiltadalafil bestellen

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.