I am new to CodeIgniter. I have found that, in order to manage multiple environments, CodeIgniter uses the following function in index.php
我是CodeIgniter的新手。我发现,为了管理多个环境,CodeIgniter在index.php中使用以下函数
define('ENVIRONMENT', 'development');
to define the environment.
定义环境。
My question is, how can I get which environment set at index.php inside my controllers?
我的问题是,我怎样才能在我的控制器中获得index.php中设置的环境?
2 个解决方案
#1
12
ENVIRONMENT
is defined in index.php
that is pipeline
of each CI application file, you can access anywhere e.g model, view, controller, library
ENVIRONMENT在index.php中定义,它是每个CI应用程序文件的管道,您可以访问任何地方,例如模型,视图,控制器,库
echo ENVIRONMENT;
#2
2
In your index.php file, try something like this:
在index.php文件中,尝试以下方法:
if ($_SERVER['HTTP_HOST'] == 'dev' || $_SERVER['HTTP_HOST'] == 'localhost')
{
define('ENVIRONMENT', 'development');
}
elseif ($_SERVER['HTTP_HOST'] == 'staging.example.com')
{
define('ENVIRONMENT', 'staging');
}
else
{
define('ENVIRONMENT', 'production');
}
Obviously, set it up with values that make sense for you. However, this will set the ENVIRONMENT based on where the application is running, automatically.
显然,使用对您有意义的值进行设置。但是,这将根据应用程序的运行位置自动设置环境。
#1
12
ENVIRONMENT
is defined in index.php
that is pipeline
of each CI application file, you can access anywhere e.g model, view, controller, library
ENVIRONMENT在index.php中定义,它是每个CI应用程序文件的管道,您可以访问任何地方,例如模型,视图,控制器,库
echo ENVIRONMENT;
#2
2
In your index.php file, try something like this:
在index.php文件中,尝试以下方法:
if ($_SERVER['HTTP_HOST'] == 'dev' || $_SERVER['HTTP_HOST'] == 'localhost')
{
define('ENVIRONMENT', 'development');
}
elseif ($_SERVER['HTTP_HOST'] == 'staging.example.com')
{
define('ENVIRONMENT', 'staging');
}
else
{
define('ENVIRONMENT', 'production');
}
Obviously, set it up with values that make sense for you. However, this will set the ENVIRONMENT based on where the application is running, automatically.
显然,使用对您有意义的值进行设置。但是,这将根据应用程序的运行位置自动设置环境。