This article analyzes the CodeIgniter configuration config.php usage example. Share it with everyone for your reference, the details are as follows:
Configuration instructions
$config['language']: Specify the project language package. It should be noted that Codeigniter's own class library error message language package is located in the /system/language/english/ directory. When non-english is configured here, if you need to use these class libraries, you need to copy the language package to the specified directory. , otherwise a load error will occur.
$config['charset']: Set the encoding used by the system. It is used in some functions that need to specify the encoding. The system and database can be encoded uniformly.
$config['enable_hooks']: Hook switch control, set to true to allow the use of hooks, otherwise not.
$config['subclass_prefix']: Set the prefix of custom class libraries and functions. The default is MY_. For example, if you need to rewrite the lang method in the language helper, you only need to create it in the helper directory. MY_language_herper.php, and implement the lang function to achieve "overloading". Here MY_ is the value defined in subclass_prefix.
$config['permitted_uri_chars']: Set the characters allowed in the URL.
$config['log_threshold']: Set the logging level. If it is 0, it will turn off logging, if it is 4, it will record all information. Generally, it can be set to 1. After setting up, you need to confirm whether the logs directory has write permission.
$config['proxy_ips']: When the server uses a proxy, REMOTER_ADDR obtains the IP of the proxy server, which needs to be obtained from HTTP_X_FORWARDED_FOR, HTTP_CLIENT_IP, HTTP_X_CLIENT_IP, HTTP_X_CLUSTER_CLIENT_IP or other set values. Get. What is set here is the IP of the proxy server, separated by commas.
$config['encryption_key']: encryption value. If you want to use the SESION that comes with CI, you must set this value. CI's own SESSION storage and cookies are encrypted for security reasons.
Configuration reading
During the CI initialization process, the config.php file will be loaded through the get_config function, and config_item is also provided to obtain the config value, such as:
Copy code The code is as follows: echo config_item('charset');
CI also provides a configuration class for maintaining configuration files. The value of config can also be obtained and set in the following way. The result of calling get_config will also change after setting, so the value of config can be modified before certain logic.
//获取config中配置的charset值 echo $this->config->item('charset'); //重新设置config中charset的值 $this->config->set_item('charset', 'gbk')
Readers who are interested in more content related to the CodeIgniter framework can check out the special topic on this site: "Introduction to codeigniter tutorial"
I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.