【问题标题】:Production and development CakeEmail settings制作开发 CakeEmail 设置
【发布时间】:2013-07-22 10:44:11
【问题描述】:

我希望在 CakePHP 应用程序中设置不同的开发和生产电子邮件环境。

/app/Config/email.php 的文档中明确指出:

You can specify multiple configurations for production, development and testing.

我的问题很简单,怎么做?

我知道您可以在此配置文件中设置许多配置,即

class EmailConfig {
    public $default = array(
        ...
    );

    public $production = array(
        ...
    );
}

我也知道,要选择给定的配置,您可以执行类似的操作

$email  = new CakeEmail('production');

我所追求的是根据我们是在开发服务器还是生产服务器上选择配置的最佳方式。

【问题讨论】:

  • 我使用我的 EmailLib 类在内部处理这个问题(使用配置配置设置)。可能不是最干净的方法。但到目前为止,它对我来说非常有效:dereuromark.de/2012/03/30/introducing-the-emaillib
  • 在你的 AppController 的 beforeFilter 函数中检查调试模式。比如 if( Configure::read('debug') == 0) { $email = new CakeEmail('production'); } else { $email = new CakeEmail('development'); }
  • @ScrappyCocco,考虑到发送电子邮件可能是一个相当罕见的事件,我有点不愿意为每个页面视图加载电子邮件配置。这似乎是不必要的开销。

标签: email cakephp cakephp-2.0


【解决方案1】:

在 EmailConfig 的构造函数中检查。

public function __construct()

【讨论】:

猜你喜欢
  • 2020-03-24
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 2023-04-11
  • 2010-11-21
  • 1970-01-01
  • 2012-05-24
  • 1970-01-01
相关资源
最近更新 更多