1.有两种方法来加载自定义配置文件(如enums.php):php
<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); $config['enums']['memcache'] = array( array('host' => '192.168.1.1', 'port' => 11211) ); $config['enums']['test'] = array( array('one' => '192.168.1.1', 'two' => 11211) );
(1)手动加载:数组
$this->load->config('enums');//注config()另外还能够有两个参数,一个是避免冲突,另外一个是屏蔽不存在这个文件而出现的报错。app
$res = $this->config->config['enums'];this
返回的结果: Array ( [memcache] => Array ( [0] => Array ( [host] => 192.168.1.1 [port] => 11211 ) ) [test] => Array ( [0] => Array ( [one] => 192.168.1.1 [two] => 11211 ) ) )
若是想只返回test对应的数组:spa
$res = $this->config->item('test','enums');调试
返回结果: Array ( [0] => Array ( [one] => 192.168.1.1 [two] => 11211 ) )
若是你想动态设置/改变一个现有的配置元素,你可使用:code
$this->config->set_item('enums',array('good','haha'));blog
(2)自动加载:ip
写入application/config/autoload.php文件中。it
2.调试错误时写入cache:
先在/www/cache/下建一个名为file的文件夹,并给这个file文件夹有写的权限。
$this->load->helper('common');
cache_set($key,$value);
3.CI 的 load 都有规避机制:
第二次 load->library 无效。
第二次 load->library 改为
对CI 全部须要传配置的类库通用。