CodeIgniter非常新,尝试创建自定义配置文件以将特殊变量加载到我的应用程序中.
在application/config/我创建custom.php并将以下代码放在该文件中:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
$gender = array ('male','female');
?>
Run Code Online (Sandbox Code Playgroud)
然后我打开application/config/autoload并更改了以下代码:
$autoload['config'] = array();
/* TO: */
$autoload['config'] = array('custom');
Run Code Online (Sandbox Code Playgroud)
我刷新我的应用程序并看到此错误:
Your application/config/custom.php file does not appear to contain a valid configuration array.
Run Code Online (Sandbox Code Playgroud)
我打开了一些默认的配置文件而没有看到配置数组?我究竟做错了什么?
Pra*_*lan 31
使用
$config['gender']= array ('male','female');
Run Code Online (Sandbox Code Playgroud)
代替
$gender = array ('male','female');
Run Code Online (Sandbox Code Playgroud)
用于获取配置项
$this->config->item('item_name');
Run Code Online (Sandbox Code Playgroud)
您要检索item_name的$config数组索引在哪里.
文档:CodeIgniter用户指南2.x CodeIgniter用户指南3.x.
小智 9
创建自定义配置文件:在"application/config /"下添加一个名为"custom_config.php"的新文件(或提供任何名称)并添加以下代码
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
//adding config items.
$config['gender'] = array('female', 'male');
Run Code Online (Sandbox Code Playgroud)
加载自定义配置文件: - 创建自定义配置文件后,我们需要加载它获取它的项目.对于加载自定义配置,我们有两种方法
***手动加载: - 我们可以在控制器/模型中手动加载配置文件
$this->config->load('custom_config'); //or instead your file name.
Run Code Online (Sandbox Code Playgroud)
***自动加载: - 对于自动加载配置文件,请转到"application/config/autoload.php"并在$ autoload ['config']中添加代码
$autoload['config'] = array('custom_config'); //or instead your file name.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37806 次 |
| 最近记录: |