简体   繁体   English

Symfony 4登录表单安全性FileLoaderLoadException

[英]Symfony 4 Login forms security FileLoaderLoadException

I'm actually in a new Symfony 4 project and I got an Error 我实际上在一个新的Symfony 4项目中,但出现错误

FileLoaderLoadException FileLoaderLoadException

There is no extension able to load the configuration for "security" (in /home/connexio/dev/project/config/packages/security.yaml). 没有扩展能够加载“安全性”的配置(在/home/connexio/dev/project/config/packages/security.yaml中)。 Looked for namespace "security", found "framework", "doctrine_cache", "doctrine", "doctrine_migrations", "twig" in /home/connexio/dev/project/config/packages/security.yaml (which is loaded in resource "/home/connexio/dev/project/config/packages/security.yaml"). 在/home/connexio/dev/project/config/packages/security.yaml(已加载到资源中)中查找名称空间“ security”,找到“ framework”,“ doctrine_cache”,“ doctrine”,“ doctrine_migrations”,“ twig” “ /home/connexio/dev/project/config/packages/security.yaml”)。

I guess that I didn't understand the magic tricks of this tutorial. 我想我不了解本教程的魔术。 (The undefined routes leaves me puzzled) (不确定的路线让我感到困惑)

https://symfony.com/doc/current/security/form_login_setup.html https://symfony.com/doc/current/security/form_login_setup.html

I precise that I didn't configure my config/routes.yaml cause they didn't ask to and I didn't install FOSUserBundle cause it's not a symfony 4 bundle. 我精确地说,我没有配置config/routes.yaml因为他们没有要求,并且我没有安装FOSUserBundle因为它不是symfony 4捆绑包。 Instead of that my files are quite the same. 代替的是,我的文件完全相同。

Anyone have an advice to fix it ? 有人建议修复它吗?

Thanks for reading ! 谢谢阅读 !

config/packages/security.yaml config / packages / security.yaml

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

src/Controller/SecurityController.php src / Controller / SecurityController.php

<?php  // src/Controller/SecurityController.php

namespace App\Controller;

use Symfony\Component\HttpFoundation\Request;
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 $authUtils)
    {
        // get the login error if there is one
        $error = $authUtils->getLastAuthenticationError();

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

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

templates/security/login.html.twig templates / security / login.html.twig

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../../../favicon.ico">

    <title>Signin Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="{{ asset('/css/bootstrap.min.css') }}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="signin.css" rel="stylesheet">
</head>

<body>
    <div class="container">
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
        {% if error %}
            <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
        {% endif %}

        <form action="{{ path('login') }}" method="post" class="form-signin">
            <h2 class="form-signin-heading">Please sign in</h2>

            <label for="username" class="sr-only">Username:</label>
            <input type="text" id="username" name="_username" value="{{ last_username }}" class="form-control" required autofocus/>

            <label for="password" class="sr-only">Password:</label>
            <input type="password" id="password" name="_password"  class="form-control" placeholder="Password" required/>

            <div class="checkbox">
                <label>
                    <input type="checkbox" value="remember-me"> Remember me
                </label>
            </div>

            {#
                If you want to control the URL the user
                is redirected to on success (more details below)
                <input type="hidden" name="_target_path" value="/account" />
            #}

            <button type="submit">login</button>
        </form>
    </div> <!-- /container -->
</body>
</html>

You are missing security component. 您缺少security组件。 Running composer req security should fix your problem. 运行composer req security应该可以解决您的问题。

For further reference check Symfony 4 documentation - Security 有关更多参考,请查看Symfony 4文档-安全性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM