I've made a CakePHP application and would like to integrate the 
environments concept. So my app should check the current domain name and 
then automatically determine if the environment is...

 1. Development: http://development.bellewaerdefun.be
 2. Staging: http://staging.bellewaerdefun.be
 3. Production: http://bellewaerdefun.be

After doing that, every environment should have it's own variables set. 
That's perfect to make a database connection without changing the variables 
when the development file is copied to staging and/or production.

So I decided to look for an existing environment plugin and I found this 
one:
https://github.com/josegonzalez/cakephp-environments

I manually copied and installed the needed folder and files, enabled the 
plugin in bootstrap.php and made a configuration file of every environment.

DEVELOPMENT

    <?php
    
    Environment::configure('development',
    array(
    'server' => array('development.bellewaerdefun.be')
    ),
    array(
            // Site specific items
            
    'Settings.FULL_BASE_URL' => 'http://development.bellewaerdefun.be',
    
    'Email.username' => 'em...@example.com',
    'Email.password' => 'password',
    'Email.test' => 'em...@example.com',
    'Email.from' => 'em...@example.com',
    
    'logQueries' => true,
            
            // App Specific functions
            
    'debug' => 2,
            
            // Securty
            
    'Cache.disable' => true,
    'Security.salt' => 'SALT',
    'Security.cipherSeed' => 'CIPHERSEED',
            
            // Database
            
            'MYSQL_DB_HOST' => 'localhost',
            'MYSQL_USERNAME' => 'root',
            'MYSQL_PASSWORD' => '',
            'MYSQL_DB_NAME' => 'blwfun',
            'MYSQL_PREFIX' => ''
    ),
    function() {
    if (!defined('FULL_BASE_URL')) {
    define('FULL_BASE_URL', Configure::read('Settings.FULL_BASE_URL'));
    }
    }
    );
    ?>


STAGING

    <?php
    
    Environment::configure('production',
    array(
    'server' => array('bellewaerdefun.be')
    ),
    array(
            // Site specific items
            
    'Settings.FULL_BASE_URL' => 'http://bellewaerdefun.be',
    
    // Email settings (maybe deprecated in 2.x)
    'Email.username' => 'em...@example.com',
    'Email.password' => 'password',
    'Email.test' => 'em...@example.com',
    'Email.from' => 'em...@example.com',
    
    // App Specific functions
            
    'debug' => 0,
    
    // Securty
    'Security.level' => 'medium',
    'Security.salt' => 'SALT',
    'Security.cipherSeed' => 'CIPHERSEED',
            
            // Database
            
            'MYSQL_DB_HOST' => 'localhost',
            'MYSQL_USERNAME' => 'xxx',
            'MYSQL_PASSWORD' => 'xxx',
            'MYSQL_DB_NAME' => 'xxx',
            'MYSQL_PREFIX' => ''
    )
    };
    ?>


After doing all of that, I thought my application would now automatically 
check the environment, but guess what: it doesn't! It keeps returning the 
default "development" environment. That's what happens in the Environment 
class (Plugin > Environments > Lib > Environment.php):

    class Environment {
    
    public $environments = array();
    
    protected static $_instance;
    
    protected $_configMap = array(
    'security' => 'Security.level'
    );
    
    public static function &getInstance() {
    if (! self::$_instance) {
    $Environment = 'Environment';
    if (config('app_environment')) {
    $Environment = 'App' . $Environment;
    }
    
    self::$_instance = new $Environment();
    Configure::write('Environment.initialized', true);
    }
    
    return self::$_instance;
    }
    
    public static function configure($name, $params, $config = null, 
$callable = null) {
    $_this = Environment::getInstance();
    $_this->environments[$name] = compact('name', 'params', 'config', 
'callable');
    }
    
    public static function start($environment = null, $default = 
'development') {
    $_this =& Environment::getInstance();
    return $_this->setup($environment, $default);
    }
    ...


Is there anyone who has the same problem as I have with this plugin? Or 
anyone who has a good solution to make my environments work?

Thanks a lot!

Additional info:
CakePHP version = 2.7.3
PHP version = 5.3.8

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to