小编Beh*_*ari的帖子

Symfony 3.4自动服务

我正在开发Symfony 3.4中的迷你应用程序.我正在使用Guard整合身份验证过程.我创建了一个名为LoginFormAuthenticator的类,它扩展了AbstractFormLoginAuthenticator.

收货错误:

无法自动装配服务"app.security.login_form_authenticator":方法"AppBundle\Security\LoginFormAuthenticator :: __ construct()"的参数"$ em"引用类"Doctrine\ORM\EntityManager"但不存在此类服务.尝试将type-hint更改为其父项之一:interface"Doctrine\ORM\EntityManagerInterface",或接口"Doctrine\Common\Persistence\ObjectManager".

我的表单中的代码验证类:

    <?php

namespace AppBundle\Security;


use AppBundle\Form\LoginForm;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;

class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
{
    private $formFactory;
    private $em;
    private $router;

    public function __construct(FormFactoryInterface $formFactory, EntityManager $em, RouterInterface $router)
    {

        $this->formFactory = $formFactory;
        $this->em = $em;
        $this->router = $router;
    }

    public function getCredentials(Request $request)
    {
        $isLoginSubmit = $request->getPathInfo() == '/login' && $request->isMethod('POST');

        if(!$isLoginSubmit){
            return false;
        }

        $form = …
Run Code Online (Sandbox Code Playgroud)

autowired symfony symfony-3.4

6
推荐指数
1
解决办法
3827
查看次数

标签 统计

autowired ×1

symfony ×1

symfony-3.4 ×1