【问题标题】:How to get values of a config file which is autoloaded in CodeIgniter如何获取在 CodeIgniter 中自动加载的配置文件的值
【发布时间】:2012-05-07 10:15:00
【问题描述】:

我正在使用 CodeIgniter,我想自动加载电子邮件配置文件并在我的控制器、库中使用。

我将电子邮件配置添加到 config/autoload.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
...some code ...
*/
$autoload['libraries'] = array(
  'database',
  'session',
  'locale',
  'util/ScriptLoader',
  'activity/Message',
  'Auth_lib',
  'email'
);

我的 config/email.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
...some code ...
*/
$config['useragent']       = "CodeIgniter";
$config['mailpath']        = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol']        = "mail";
$config['smtp_host']       = "localhost";
$config['smtp_user']       = "";
$config['smtp_pass']       = "";
$config['smtp_port']       = "25";
$config['system_email']    = "noreply@xxxx.com";
$config['help_email']      = "help@xxxxx.com";
$config['inquiries_email'] = "inquiries@xxxx.com";
$config['support_email']   = "support@xxxx.com";

我尝试使用

在我的控制器中获取 support_email
$this->config->item('support_email')

但不起作用,如何在控制器中获取自动加载的值?请帮忙

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    你需要在$autoload['config'] = 'email';下自动加载配置文件

    【讨论】:

      【解决方案2】:

      如果你不需要自动加载,

      1) Place the email.php under application/config
      2) In your controller
      
         $this->config->load('email');
         $this->config->item('support_email')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多