我的bundle扩展类(symfony 3)有什么问题?

时间:2016-02-28 11:55:51

标签: php dependency-injection symfony

我的代码:https://github.com/artemzakholodilo/murkatest/blob/master/src/MailerBundle/DependencyInjection/MailerExtension.php

如果我写./bin/console debug:container我看到这个服务

1 个答案:

答案 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');
    }

希望这个帮助