如何读取config目录下自定义的配置文件里的数组
我在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['']的数组内容?谢谢了 关注一下。估计你的是格式的问题 myconfig.php文件里面的数组格式应该为:
$config['myarray'] = array('name'=>'xiaoming'); 楼上写的让我一下豁然开朗啊 。在你自己写的配置文件中一定要用 $config 而不是用别的,我之前就是用$mytest['test'] = array().....就不行。看了高手就是一点就通啊。谢谢谢谢 haohailuo 发表于 2010-6-2 12:12 static/image/common/back.gif
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的语法理解有错误啊?请帮忙啊。谢谢啦。。。 看一下用户指南吧~~~写的很清楚的~{:1_1:}
http://codeigniter.org.cn/user_guide/libraries/config.html wy_june 发表于 2011-11-16 12:48 static/image/common/back.gif
看一下用户指南吧~~~写的很清楚的~
http://codeigniter.org.cn/user_guide/libraries/config.html ...
:handshake很有帮组
页:
[1]