CodeIgniter在数据库设置之前运行库

CodeIgniter在数据库设置之前运行库,codeigniter,codeigniter-2,Codeigniter,Codeigniter 2,我在本地主机上测试Codeigniter站点,然后在服务器上更新它。在它们之间切换涉及许多与调整相关的问题 所以我只想通过一个常量来配置它:MYCUSTOM\u SERVER\u LOCATION 然后根据服务器的位置(localhost或myhost)配置数据库连接和密码。唯一的问题是database.php在mysettingslibrary之前运行。即使在配置文件而不是库中进行设置,也会产生相同的结果 [更新] application/config/autoload.php: ... $

我在本地主机上测试Codeigniter站点,然后在服务器上更新它。在它们之间切换涉及许多与调整相关的问题

所以我只想通过一个常量来配置它:
MYCUSTOM\u SERVER\u LOCATION

然后根据服务器的位置(localhost或myhost)配置数据库连接和密码。唯一的问题是database.php在
mysettings
library之前运行。即使在配置文件而不是库中进行设置,也会产生相同的结果

[更新]


application/config/autoload.php:

...
$autoload['libraries'] = array('mysettings','database','session');
...

application/libraries/mysettings.php:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

define("MYCUSTOM_SERVER_LOCATION", "localhost");

class mysettings {

//////////////////////////////////////////////////
// option: localhost
// option: 000webhost
//$config["mycustom_server"]="localhost";

}

输出结果:

A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant MYCUSTOM_SERVER_LOCATION - assumed 'MYCUSTOM_SERVER_LOCATION'
Filename: config/database.php
Line Number: 51


A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant MYCUSTOM_SERVER_LOCATION - assumed 'MYCUSTOM_SERVER_LOCATION'
Filename: config/database.php
Line Number: 58


Unknown server.

您可以在
application/config/database.php

用法示例:

/* 
 The $active_group variable lets you choose which connection group to
 make active.  By default there is only one group (the 'default' group).
*/

$active_group = "development";

$db['development']['hostname'] = "localhost";
$db['development']['username'] = "us";
$db['development']['password'] = "";
$db['development']['database'] = "db1";

你试过用钩子吗?我认为这是您需要的,因为您的问题更新了以前的错误,因为在常量之前使用$@托梅克桑,我不知道钩子。他们在这种情况下有帮助吗?(不触摸系统文件夹)@germar一个简单的开关就可以了。activerecord变量是CI知道要加载哪些数据库设置的位置。
/* 
 The $active_group variable lets you choose which connection group to
 make active.  By default there is only one group (the 'default' group).
*/

$active_group = "development";

$db['development']['hostname'] = "localhost";
$db['development']['username'] = "us";
$db['development']['password'] = "";
$db['development']['database'] = "db1";