Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Symfony 4中创建登录页面而不出现错误;InvalidConfigurationException";?_Php_Symfony_Security_Login_Error Handling - Fatal编程技术网

Php 如何在Symfony 4中创建登录页面而不出现错误;InvalidConfigurationException";?

Php 如何在Symfony 4中创建登录页面而不出现错误;InvalidConfigurationException";?,php,symfony,security,login,error-handling,Php,Symfony,Security,Login,Error Handling,config/packages/security.yaml: security: encoders: App\Entity\User: algorithm: bcrypt # ... providers: our_db_provider: entity: class: App\Entity\User property: username

config/packages/security.yaml:

security:
  encoders:
    App\Entity\User:
      algorithm: bcrypt

      # ...

      providers:
        our_db_provider:
          entity:
            class: App\Entity\User
            property: username
            # if you're using multiple entity managers
            # manager_name: customer

            firewalls:
              main:
                anonymous: ~
                form_login:
                  login_path: login
                  check_path: login

                  # ...
                  access_control:
                    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
                    - { path: ^/, roles: ROLE_ADMIN }
src/Controller/SecurityController.php:

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;

class SecurityController extends Controller
{
  /**
  * @Route("/login", name="login")
  */
  public function login(Request $request, AuthenticationUtils $authenticationUtils)
  {
      // get the login error if there is one
      $error = $authenticationUtils->getLastAuthenticationError();

      // last username entered by the user
      $lastUsername = $authenticationUtils->getLastUsername();

      return $this->render('security/login.html.twig', array(
          'last_username' => $lastUsername,
          'error'         => $error,
      ));
  }
}

您的security.yaml配置中的制表错误。你有这个:

security:
  encoders:
    App\Entity\User:
      algorithm: bcrypt

      # ...

      providers:
它应该是:

security:
  encoders:
    App\Entity\User:
      algorithm: bcrypt

      # ...

  providers:

编码器
提供者
都应该是
安全
配置下的一级子项。

谢谢,这解决了大多数错误。但仍然存在此错误:
无法确定“App\controller\SecurityController::login()”的控制器参数:$request参数的类型暗示了不存在的类或接口:“App\controller\request”。忘记添加use语句了吗?
add
use-Symfony\Component\HttpFoundation\Response到您的
安全控制器
类的顶部谢谢您的建议。我做到了,但仍然是相同的错误oops我的意思是
使用Symfony\Component\HttpFoundation\Request是的,我正在处理文档,我通过文档创建了此登录,但是我才刚刚开始,所以仍然存在一些问题:)但是非常感谢您的帮助!!真的:)
security:
  encoders:
    App\Entity\User:
      algorithm: bcrypt

      # ...

      providers:
security:
  encoders:
    App\Entity\User:
      algorithm: bcrypt

      # ...

  providers: