实际上,我正在一个新的Symfony 4项目中,我遇到了一个错误
FileLoaderLoadException 没有能够加载“安全性”配置的扩展(在/home/connexio/dev/project/config/packages/security.yaml).中)查找名称空间“安全”,在/home/connexio/dev/project/config/packages/security.yaml中找到“框架”、"doctrine_cache“、”原则“、"doctrine_migrations”、“小枝”(它加载在资源"/home/connexio/dev/project/config/packages/security.yaml").中)。
我想我不懂这个教程的魔术。(路线未定,令我费解)
我准确地说,我没有配置我的config/routes.yaml,因为他们没有要求,我也没有安装FOSUserBundle,因为它不是symfony 4包。相反,我的文件是完全一样的。
有人有什么建议来解决这个问题吗?
谢谢你的阅读!
config/packages/security.yaml
security:
firewalls:
main:
anonymous: ~
form_login:
login_path: login
check_path: loginsrc/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
<!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>发布于 2018-01-11 17:10:27
您缺少security组件。运行composer req security应该可以解决问题。
如需进一步参考,请检查Symfony 4文档-安全性
https://stackoverflow.com/questions/48212411
复制相似问题