我是ZF2的新手,我不了解ZF2应用程序的配置。
例如,转换是在模块的配置中配置的。如果使用来自不同来源的模块,这似乎是一个好方法。但所以我必须为每个模块翻译相同的东西 - 这不是一种有效的方法。 邮件运输也是如此。 Normaly我想以同样的方式发送我的Web应用程序的所有邮件(Sendmail或Smtp)。
是否有解决方案将此配置从模块的配置移动到全局配置?特别是对于使用第三方模块?
此致 Bytecounter
答案 0 :(得分:1)
只是别名服务:
return [
'service_manager' => [
'aliases' => [
'PhlyContactMailTransport' => 'MailTransport',
],
'factories' => [
'MailTransport' => function (ServiceManager $serviceManager) {
// create your transport
return $transport;
},
],
],
];
供参考,见
答案 1 :(得分:0)
我在文件夹config/autoload/mail.global.php
喜欢这个
return [
'service_manager' => [
'factories' => [
'MailTransport' => function ($sm) {
$transport = new \Zend\Mail\Transport\File();
$options = new \Zend\Mail\Transport\FileOptions([
'path' => './data/mail',
'callback' => function (\Zend\Mail\Transport\File $transport) {
return 'Message_' . date('d_m_Y H_i') . '__' . mt_rand() . '.eml';
},
]);
$transport->setOptions($options);
return $transport;
}
]
]
];
并在$this->getServiceManager()->get('MailTransport');