1

我正在使用 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'
);

我的配置/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')

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

4

2 回答 2

4

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

于 2012-05-07T10:31:14.850 回答
3

如果您不需要自动加载它,

1) Place the email.php under application/config
2) In your controller

   $this->config->load('email');
   $this->config->item('support_email')
于 2012-05-07T10:39:15.843 回答