Php 如何在Symfony 4中创建登录页面而不出现错误;InvalidConfigurationException";?
config/packages/security.yaml: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
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语句了吗?
adduse-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: