如果我写./bin/console debug:container我看到这个服务
答案 0 :(得分:2)
似乎是您的controller is not defined as a service,因此您可以将控制器中的服务用作:
/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function sendAction(Request $request)
{
$notification = new Notification();
$user = $this->get('security.token_storage')->getToken()->getUser();
$notification->setBody($request->request->get('subject'), $user->getUsername());
$notification->setSubject($request->request->get('body'));
try {
$this->get('emailsender')->send($notification);
} catch (\Exception $ex) {
$this->render('MailerBundle:Email:error.html.twig', [
'message' => $ex->getMessage()
]);
}
$this->render('MailerBundle:Email:success.html.twig');
}
希望这个帮助