CI框架中自定义配置文件

PHP piniu 752浏览 0评论

我们有时候在CI框架中需要自定义配置文件,那要怎么处理呢?

下面就给你介绍处理的办法。
1.在 application/config 目录下新建 自定义配置文件:expert.php

<?php
 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* 专家配置文件
*
* @author xxx
* @version $Id: expert.php v 1.0 2012/5/31 14:41:00 xxx $
* @package ask.xxx.com
* @copyright 1997-2012 www.xxx.com
*/
// 专家ID
$config['expertid'] = array('0' => '124', '1' => '81', '2' => '136');

2. 获取配置数据示例

//可在你的控制器的构造函数中加载和获取配置 也可在具体的控制器下的方法/函数中 使用。
$this->config->load('expert', TRUE);
$expertid = $this->config->item('expertid', 'expert');

//附: CI自定义配置文件  http://codeigniter.org.cn/user_guide/libraries/config.html


发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • * 昵称:
  • * 邮箱: