我的捆绑扩展类(symfony 3)有什么问题


What is wrong with my bundle extension class ( symfony 3 )?

my code: https://github.com/artemzakholodilo/murkatest/blob/master/src/MailerBundle/DependencyInjection/MailerExtension.php

如果我写 ./bin/console 调试:容器,我会看到这个服务

似乎您的控制器未定义为服务,因此您可以在控制器中将该服务用作:

/**
     * @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');
    }

希望这个帮助