【发布时间】: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