ContextErrorException: Catchable Fatal Error: Argument 4 passed to Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::__construct() must be an array,null given,called in D:\xampp\htdocs\essweb\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider.PHP on line 96 and defined in D:\xampp\htdocs\essweb\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken.PHP line 36
Security.yml
firewalls: admin_area: pattern: ^/ anonymous: ~ form_login: login_path: / check_path: /login_check default_target_path: /user failure_path: / #username_parameter: username #password_parameter: password remember_me: true remember_me: key: "%secret%" lifetime: 31536000 path: / domain: ~ always_remember_me: true logout: path: /logout target: /
更新:
登录表格:
<form class="form-signin form-group" action="{{ path('login_check') }}" method="post"> Username: <input type="text" class="form-control" name="_username" placeholder="Username" value="{{ last_username }}" required="required"> Password: <input type="text" class="form-control" name="_password" placeholder="" value="{{ last_username }}" required="required"> <button class="btn btn-sm btn-primary btn-block" type="submit">Sign in</button>
UsernamePasswordToken::__construct()
的第四个参数应该是一个数组,但它是null.它在UserAuthenticationProvider
at line 96被召集.
如果您查看该代码,您将看到UsernamePasswordToken :: __ construct()的第4个参数是$roles.所以这应该是一个数组,但它变为null.
我猜你有written your own User entity,并且你的用户实体的getRoles()方法返回null而不是一组角色.所以只需将该方法更改为:
/** * Returns the roles granted to the user. * * @return Role[] The user roles */ public function getRoles() { return array('ROLE_USER'); }
当然,只要getRoles()返回字符串数组或Role对象,实际代码可能会有所不同(您可能希望将用户角色存储在数据库中).