[英]Symfony Fosuserbundle resend email
我正在尝试建立一个链接,该链接在Symfony3中注册后向用户重新发送确认令牌。
但是,我收到以下弃用消息:
不推荐使用的用户:“ fos_user.mailer”服务是私有的,从Symfony 3.2开始不推荐从容器中获取它,并且在4.0中将失败。 您应该公开服务,或者直接停止使用容器,而改用依赖项注入。
这是我的控制器:
public function resendActivationEmail($token, UserManagerInterface $userManager)
{
$user = $userManager->findUserByConfirmationToken($token);
if (is_null($user)) {return $this->redirectToRoute('fos_user_registration_register');}
$mailer = $this->get('fos_user.mailer');
$mailer->sendConfirmationEmailMessage($user);
return $this->redirectToRoute('fos_user_registration_check_email');
}
我的services.yml:
services:
# default configuration for services in *this* file
_defaults:
autowire: truesubscribers, etc.
autoconfigure: true
public: false
我查看了文档,它说在Symfony3.4中,默认情况下服务是私有的。 我在我的应用程序中使用自动装配,那么如何获得fos_user.mailer
而没有任何弃用警告?
我尝试将Fosuserbundle服务设置为公共服务,没有帮助:
services.yml
:
....
FOS\UserBundle:
public: true
任何帮助表示赞赏!
使用$mailer = $this->container->get('fos_user.mailer');
而不是$mailer = $this->get('fos_user.mailer');
最好使用DependencyInjection而不是直接调用容器。 您应该将邮件传递给您的方法:
public function resendActivationEmail($token, UserManagerInterface $userManager, \FOS\UserBundle\Mailer\MailerInterface $mailer)
{
$user = $userManager->findUserByConfirmationToken($token);
if (is_null($user)) {return $this->redirectToRoute('fos_user_registration_register');}
$mailer->sendConfirmationEmailMessage($user);
return $this->redirectToRoute('fos_user_registration_check_email');
}
有关DependencyInjection的更多信息: https : //symfony.com/doc/3.4/service_container/injection_types.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.