如何分隔 codeigniter v3.1.10 中特定的 config.php、database.php、constant.php 文件域?
how to separate config.php, database.php, constant.php file domain specific in codeigniter v3.1.10?
我正在使用 codeigniter v3.1.10
,我有两个域名为 abc.example.com
和 xyz.example.com
的项目。我知道在 codeigniter 中,根据环境生产或开发,我们可以在配置文件夹中添加文件夹 application/config/production
和 application/config/development
,其中包含它们各自的文件。 SO 中的一个示例:-multiple environments with codeigniter,为我们提供了在 application/config
文件夹中添加 development/production
文件夹的规定。
但我要找的是 domain specific folders inside application/config folder
。有没有一种方法可以将 application/config/abc.example.com
和 application/config/xyz.example.com
等两个文件夹放入 config.php, database.php and constant.php
文件。
根据您的要求,您需要配置多个子域。
例如,子域 abc.exmaple.com
想要加载 abc
配置文件夹。
对于子域 xyz.exmaple.com
想要加载 xyz
配置文件夹。
在你的index.php
$env= 'development';
list($subdomain,$host) = explode('.', $_SERVER["SERVER_NAME"]);
$allowed_subdomains = ['abc','xyz'];
$env = in_array($subdomain,$allowed_sbudomains) ? $subdomain : $env;
define('ENVIRONMENT',$env);
在下面的 switch..case
中作为您的子域的案例
switch (ENVIRONMENT)
{
...
...
case 'testing':
case 'production':
case $subdomain:
....
}
现在在 config 文件夹下根据您的子域创建一个文件夹,并在那里进行所需的配置。
我正在使用 codeigniter v3.1.10
,我有两个域名为 abc.example.com
和 xyz.example.com
的项目。我知道在 codeigniter 中,根据环境生产或开发,我们可以在配置文件夹中添加文件夹 application/config/production
和 application/config/development
,其中包含它们各自的文件。 SO 中的一个示例:-multiple environments with codeigniter,为我们提供了在 application/config
文件夹中添加 development/production
文件夹的规定。
但我要找的是 domain specific folders inside application/config folder
。有没有一种方法可以将 application/config/abc.example.com
和 application/config/xyz.example.com
等两个文件夹放入 config.php, database.php and constant.php
文件。
根据您的要求,您需要配置多个子域。
例如,子域 abc.exmaple.com
想要加载 abc
配置文件夹。
对于子域 xyz.exmaple.com
想要加载 xyz
配置文件夹。
在你的index.php
$env= 'development';
list($subdomain,$host) = explode('.', $_SERVER["SERVER_NAME"]);
$allowed_subdomains = ['abc','xyz'];
$env = in_array($subdomain,$allowed_sbudomains) ? $subdomain : $env;
define('ENVIRONMENT',$env);
在下面的 switch..case
中作为您的子域的案例
switch (ENVIRONMENT)
{
...
...
case 'testing':
case 'production':
case $subdomain:
....
}
现在在 config 文件夹下根据您的子域创建一个文件夹,并在那里进行所需的配置。