Developers often want to be able to behave differently when the system is running in a development environment or production environment , for example, in a development environment where a program can output detailed error messages, but in a production environment this creates some security issues.
Environment constants
The CodeIgniter default uses the value of $_server[' ci_env '] as the environment constant, and if the value of $_server[' ci_env ' is not set, it is set to ' development '. at the top of the index.php file , you can see:
Define ('environment', isset ($_server['ci_env'])? $_server[ ' ci_env ' ' Development ');
1. The value of $_server[' ci_env '] can be set in the. htaccess file or in the Apache configuration file using the SetEnv command (Nginx or other Web server also has a similar setup method).
2, or you can delete this logic directly, according to the server's IP address to set the constant.
The use of this constant, in addition to affecting some basic framework behavior, can also be used during the development process to distinguish between what is currently running environment.
Impact on default framework behavior
There are several places in the CodeIgniter system where environment constants are used. Ring.
Error Reporting
If you set the environment constant to ' development ', the error message appears on the browser when a PHP error occurs.
In contrast, if you set the constant to ' production ' the error output is disabled.
Configuration file
In addition, CodeIgniter can load different configuration files depending on the environment, which is useful when dealing with different API keys for example in different environments. This is described in more detail in the "Environment" section of the configuration class documentation.
CI Framework--development environment, production environment