CakePhp:Cake Email AfterSend事件
大家早上好,
我目前正在使用CakePHP. CakeEmail类不提供回调方法,我没有找到任何方法来调用这种事件而不编辑CakeEmail类. 你有什么建议? (抱歉英文不好,不是我的母语)
使用自定义记录器:
Implement your own logger具有您想要的数据库功能,并在引导程序中为电子邮件范围配置它,这是电子邮件日志的默认范围或更改电子邮件类配置中的整个日志记录. See this part of the email class. 1161: $contents = $this->transportClass()->send($this); 1162: if (!empty($this->_config['log'])) { 1163: $config = array( 1164: 'level' => LOG_DEBUG,1165: 'scope' => 'email' 1166: ); 1167: if ($this->_config['log'] !== true) { 1168: if (!is_array($this->_config['log'])) { 1169: $this->_config['log'] = array('level' => $this->_config['log']); 1170: } 1171: $config = $this->_config['log'] + $config; 1172: } 1173: CakeLog::write( 1174: $config['level'],1175: PHP_EOL . $contents['headers'] . PHP_EOL . $contents['message'],1176: $config['scope'] 1177: ); 1178: } 使用你自己的班级 – 但做得对
那么你可以使用自己的电子邮件类.但是在代码中到处都是新的SomeClass(),无论如何都不是好事.你只知道原因.另一个不容易测试的原因. 而是在继承链的上层(AppController,AppModel …)的某些类中执行此操作: public function getEmailInstance($config = null) { return new MyEmailClass($config); } 这允许您简单地“全局”更改类,并在测试中模拟方法. 如果您使用的是PHP 5.4(或5.5,现在还不确定),您也可以使用它的特性,并仅在需要该功能的类中使用它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |