CI Framework--development environment, production environment

Source: Internet
Author: User
Tags php error codeigniter

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.