用户
 找回密码
 入住 CI 中国社区
搜索
查看: 9861|回复: 6
收起左侧

[已解决] 如何读取config目录下自定义的配置文件里的数组

[复制链接]
发表于 2010-6-2 11:10:42 | 显示全部楼层 |阅读模式
我在config目录下新建了myconfig.php,里面写了诸如 $myarray=array('name'=>'xiaoming');的数组,请问我在controller里如何读取$myarray的数组,用$this->config->load()的方式报错”Your mimes.php file does not appear to contain a valid configuration array.
“,好像只能读取数组格式为$myconfig['']的数组内容?谢谢了
发表于 2010-6-2 11:16:41 | 显示全部楼层
关注一下。估计你的是格式的问题
发表于 2010-6-2 12:12:47 | 显示全部楼层
myconfig.php文件里面的数组格式应该为:
$config['myarray'] = array('name'=>'xiaoming');
发表于 2011-6-24 16:34:32 | 显示全部楼层
楼上写的让我一下豁然开朗啊 。在你自己写的配置文件中一定要用 $config 而不是用别的,我之前就是用$mytest['test'] = array().....就不行。看了高手就是一点就通啊。谢谢谢谢
发表于 2011-11-16 10:07:31 | 显示全部楼层
haohailuo 发表于 2010-6-2 12:12
myconfig.php文件里面的数组格式应该为:
$config['myarray'] = array('name'=>'xiaoming');

版主啊,你好,有个问题想请教下你,我该怎么在controller里面加载我的config.php文件啊,我想读取config.php文件里面数组的内容。我的control文件如下:
<?php
class Start extends CI_Controller {
    var $base;
    var $css;
        function Start()
        {
                #parent::CI_Controller();
                $this->config->load('config');
                $this->base = $this->config->item('base_url','config');
                $this->css = $this->config->item('css');
                echo $config['css'];
        }
        function index()
        {
                $data['css'] = $this->css;
                $data['base'] = $this->base;
                $data['mytitle'] = 'Welcome to this site';
                $data['mytext'] = "Hello, now we're getting dynamic!";
                #$this->load->view('testview', $data);
        }
}
?>
可是会保错:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Start:config

Filename: controllers/start.php

Line Number: 8

Fatal error: Call to a member function load() on a non-object in D:\phpnow\htdocs\CodeIgniter\application\controllers\start.php on line 8
是不是我对codeigniter的语法理解有错误啊?请帮忙啊。谢谢啦。。。
发表于 2011-11-16 12:48:19 | 显示全部楼层
看一下用户指南吧~~~写的很清楚的~
http://codeigniter.org.cn/user_guide/libraries/config.html
发表于 2011-11-16 16:40:14 | 显示全部楼层
wy_june 发表于 2011-11-16 12:48
看一下用户指南吧~~~写的很清楚的~
http://codeigniter.org.cn/user_guide/libraries/config.html ...

很有帮组

本版积分规则