我正在尝试使用Sonata Admin Bundle
发送电子邮件的自定义批处理操作。
问题是,我不确定如何访问 swiftmailer。我有以下内容:
public function batchActionSend(ProxyQueryInterface $selectedModelQuery)
{
if($this->admin->isGranted('EDIT')=== false) {
throw new AccessDeniedException();
}
$request = $this->get('request');
$modelManager = $this->admin->getModelManager();
$selectedModels = $selectedModelQuery->execute();
try {
foreach ($selectedModels as $selectedModel) {
// send the email here?
$selectedModel->send();
$modelManager->update($selectedModel);
}
} catch (\Exception $e) {
$this->get('session')->getFlashBag()->add('sonata_flash_error', $e->getMessage());
return new RedirectResponse($this->admin->generateUrl('list',$this->admin->getFilterParameters()));
}
$this->get('session')->getFlashBag()->add('sonata_flash_success', sprintf('The selected requests have been sent'));
return new RedirectResponse($this->admin->generateUrl('list',$this->admin->getFilterParameters()));
在我的实体中,我有以下内容:
public function send()
{
// send email here?
}
访问邮件程序的最佳方式是什么?通过管理类或通过实体或通过服务?
谢谢