CodeIgniter3:为什么首先要设置$ _SERVER ['CI_ENV']? [英] CodeIgniter3: Why would $_SERVER['CI_ENV'] ever be set in the first place?
问题描述
我看到他们的默认安装中,他们的index.php具有以下内容:
I see that in their default installation, their index.php has this:
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
为什么要在$_SERVER
数组中设置
Why would CI_ENV
ever already be set within the $_SERVER
array?
推荐答案
如Oliver所述;这是针对多种环境的特殊用例.分开进行开发,测试和测试通过.htaccess
进行生产之前,甚至还没有到达代码.要配置它:
As Oliver described; it's a special-use case for multiple environments. Splitting out the development, testing & production by means of .htaccess
before it even gets to the code. To configure this:
<IfModule mod_env.c>
SetEnv CI_ENV development
</IfModule>
测试(您的本地服务器)
<IfModule mod_env.c>
SetEnv CI_ENV testing
</IfModule>
生产(远程服务器)
<IfModule mod_env.c>
SetEnv CI_ENV production
</IfModule>
您正确地认为,除非有一些手动干预,否则它永远不会改变.关于这一点的文档不多:
You're right in thinking it won't ever change unless there's some manual intervention. There's not much documentation in regards to this:
此服务器变量可以在.htaccess文件中设置,也可以使用SetEnv在Apache配置中设置.nginx和其他服务器也可以使用其他方法,也可以完全删除此逻辑并根据服务器的IP地址设置常量. "
"This server variable can be set in your .htaccess file, or Apache config using SetEnv. Alternative methods are available for nginx and other servers, or you can remove this logic entirely and set the constant based on the server’s IP address."
来源:> 使用环境常数 >
Source: Using the Environment Constant
这篇关于CodeIgniter3:为什么首先要设置$ _SERVER ['CI_ENV']?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!