关于引用文件的问题
config目录下我新建了一个文件叫commfun.php,里面我写了些共同的方法。我想在哪个地方引用下,让所有PHP页面都能引用这个文件里的方法。
好像在autoload.php这个文件里设置就行,请问该怎么写呢? 本帖最后由 zycbob 于 2010-4-12 17:56 编辑
config文件里不是写方法的地方,要写到自己的类库里。你的类库文件必须保存在 application/libraries 文件夹,CodeIgniter将在这个文件夹中寻找并初始化它们.
$this->load->library('someclass');
$this->someclass->some_function();// 对象的实例名永远都是小写的
http://codeigniter.org.cn/user_guide/general/creating_libraries.html
如果要配置config下的文件
参见
1.手动加载
$this->config->load('commfun');
2.自动加载
autoload.php 82line
$autoload['config'] = array('commfun');
获取
$this->config->item('item name');
设置
$this->config->set_item('item_name', 'item_value');
参见
http://codeigniter.org.cn/user_guide/libraries/config.html
页:
[1]