codeigniter的自定义配置文件 [英] Custom config file for codeigniter

查看:123
本文介绍了codeigniter的自定义配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CodeIgniter非常新,尝试创建一个自定义配置文件来加载特殊变量到我的应用程序。



application / config / 中创建 custom.php 并将以下代码放在该文件中:

 <?php if(!defined('BASEPATH'))exit '不允许直接脚本访问'); 

$ gender = array('male','female');

?>

然后我打开 application / config / autoload 并更改了以下代码:

  $ autoload ['config'] = array 

/ * TO:* /

$ autoload ['config'] = array('custom');

我刷新了我的申请,看到这个错误:

 您的application / config / custom.php文件似乎不包含有效的配置数组。 

我打开了一些默认配置文件,看不到配置数组?

pre






$ config ['gender'] = array('male','female');

而不是

  $ gender = array('male','female'); 

获取配置项

  $ this-> config-> item('item_name'); 

其中 item_name $ config 要检索的数组索引。



文件: CodeIgniter用户指南2.x CodeIgniter用户指南3.x


Very new to CodeIgniter, trying to create a custom config file to load special variables into my application.

in application/config/ I created custom.php and placed the following code in that file:

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

$gender = array ('male','female'); 

?>

I then opened up application/config/autoload and altered the following code:

$autoload['config'] = array();

/* TO: */ 

$autoload['config'] = array('custom');

I refresh my application and see this error:

Your application/config/custom.php file does not appear to contain a valid configuration array.

I opened up some of the default config files and don't see a configuration array? What am I doing wrong?

解决方案

Use

$config['gender']= array ('male','female');

instead of

$gender = array ('male','female');

For fetching config item

$this->config->item('item_name');

Where item_name is the $config array index you want to retrieve.

Docs : CodeIgniter User Guide 2.x CodeIgniter User Guide 3.x

这篇关于codeigniter的自定义配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆