Skip to content

Instantly share code, notes, and snippets.

@alextucker
Created February 28, 2011 23:24
Show Gist options
  • Save alextucker/848266 to your computer and use it in GitHub Desktop.
Save alextucker/848266 to your computer and use it in GitHub Desktop.
Selecting Kohana enviroment
<?php
if ($_SERVER['SERVER_NAME'] == 'localhost' ) {
Kohana::$environment = Kohana::DEVELOPMENT;
} else {
Kohana::$environment = Kohana::PRODUCTION;
}
@ariews
Copy link

ariews commented Mar 13, 2013

I love this:

Kohana::$environment = Kohana::DEVELOPMENT;

if (isset($_SERVER['KOHANA_ENV']))
{
    Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
}

and for config:

/**
 * Attach a file reader to config. Multiple readers are supported.
 */
Kohana::$config->attach(new Config_File);

// Custom config file
switch (Kohana::$environment):
    case Kohana::PRODUCTION:  $config_dir = 'config/production';  break;
    case Kohana::STAGING:     $config_dir = 'config/staging';     break;
    case Kohana::TESTING:     $config_dir = 'config/testing';     break;
    case Kohana::DEVELOPMENT: $config_dir = 'config/development'; break;
endswitch;

Kohana::$config->attach(new Config_File($config_dir));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment