/ Published in: PHP
Instead of having multiple configurations for multiple domains, and the numerous if/then/else statements not to mention the various locations for storing the configuration....instead, enable hooks in your application config and then add this snippet of code into your application hooks directory.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class System_Config { // First host should be the production server. 'type' => 'mysql', 'user' => 'user', 'pass' => 'password', 'host' => 'localhost', 'port' => FALSE, 'socket' => FALSE, 'database' => 'example_db' ), 'config.display_errors' => FALSE, 'common.google_map_key' => '' ), 'type' => 'mysql', 'user' => 'user', 'pass' => 'password', 'host' => 'localhost', 'port' => FALSE, 'socket' => FALSE, 'database' => 'example_db' ), 'config.display_errors' => TRUE, 'unfuddle.display' => TRUE, 'license.display' => TRUE, 'common.google_map_key' => 'ABQIAAAANSflOC-DomiqtMkm0RLk0hQRum5EX2MZh7gd_I08tUb48drBLRRgcWKqtRNPur6StvJ8C2yML-gckg' ), ); public static function init() { $configs = self::$configs; $server_name = isset($_SERVER['SERVER_NAME']) ? preg_replace('#^www\.#i', '', $_SERVER['SERVER_NAME']) : $production_server; Kohana::config_set('config.in_production', $server_name == $production_server); // Enable errors if on cmd line if (PHP_SAPI == 'cli') { } // Set configuration vars if there is a config set for this hostname { // If a site domain isn't configured, defaults to server name. { $configs[$server_name]['config.site_domain'] = $_SERVER['SERVER_NAME'] . '/'; } foreach ($configs[$server_name] as $k => $v) { Kohana::config_set($k, $v); // If namespace is config, reapply it to core as well. if ($config_namespace == 'config') { if ($k == 'config.display_errors') { Kohana::config_set("core.$config_key", $v); } } } } else { } } }