【问题标题】:What is wrong with my bundle extension class ( symfony 3 )? [closed]我的捆绑扩展类( symfony 3 )有什么问题? [关闭]
【发布时间】:2016-02-28 11:55:51
【问题描述】:

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

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

【问题讨论】:

  • 那么,有什么问题?
  • 我在 EmailController 的构造方法中收到 null
  • 我在构造方法中需要 EmailSender 参数,但是给定了 null

标签: php dependency-injection symfony


【解决方案1】:

似乎是您的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');
    }

希望有帮助

【讨论】:

  • 在我的项目中也是如何写在cookbook中的
  • 现在我有 500 个 http 错误
  • 这样做: $container->setDefinition('app.hello_controller', new Definition( 'AppBundle\Controller\HelloController', array(new Reference('templating')) ));
  • php bin\console debug:container | grep email form.type.email Symfony\Component\Form\Extension\Core\Type\EmailType mailer.email_controller MailerBundle\Controller\EmailController mailer.emailsender MailerBundle\Sender\EmailSender
  • 如您所见,所有服务均已定义
猜你喜欢
  • 1970-01-01
  • 2020-04-30
  • 1970-01-01
  • 2017-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多