Php codeigniter的自定义配置文件
CodeIgniter是一个新手,尝试创建一个自定义配置文件,将特殊变量加载到我的应用程序中 在Php codeigniter的自定义配置文件,php,codeigniter,Php,Codeigniter,CodeIgniter是一个新手,尝试创建一个自定义配置文件,将特殊变量加载到我的应用程序中 在application/config/中,我创建了custom.php,并将以下代码放在该文件中: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); $gender = array ('male','female'); ?> 我刷新应用程序并看到以下错误: Your applicati
application/config/
中,我创建了custom.php
,并将以下代码放在该文件中:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
$gender = array ('male','female');
?>
我刷新应用程序并看到以下错误:
Your application/config/custom.php file does not appear to contain a valid configuration array.
我打开了一些默认配置文件,但没有看到配置阵列?我做错了什么?使用
$config['gender']= array ('male','female');
而不是
$gender = array ('male','female');
用于获取配置项
$this->config->item('item_name');
其中item\u name
是要检索的$config
数组索引
文档:创建自定义配置文件: 在“application/config/”下添加一个名为“custom_config.php”(或提供任何名称)的新文件,并添加以下代码
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
//adding config items.
$config['gender'] = array('female', 'male');
***自动加载:-对于自动加载配置文件,请转到“application/config/autoload.php”,并在$autoload['config']中添加代码
$autoload['config'] = array('custom_config'); //or instead your file name.
编码点火器3
步骤1:创建自定义配置文件
/path/to/codeigniter/application/config/custom.php
步骤2:加载自定义配置文件
这可以在模型或控制器内完成
//加载配置文件
$this->config->load('custom');
//检索特定配置的内容
$server=$this->config->item('server');
//$server现在已设置
echo$server['host'];//example.com
$gender=$this->config->item('gender');//返回arrayAlso,您可以使用$this->load->config('custom_config')加载配置文件。
$this->config->load('custom_config'); //or instead your file name.
$autoload['config'] = array('custom_config'); //or instead your file name.