Я использую symfony 2.8, я новичок в symfony, я внедрил логин и регистрацию, регистрация работает нормально, но когда я вхожу в систему, она показывает эту ошибку
Type error: Argument 4 passed to Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::__construct() must be of the type array, string given,
called in C:\xampp\htdocs\blog\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider.php on line 96
Теперь я немного запутался в реализации ROLES, у меня есть таблица пользователей в БД,
ТАБЛИЦА ПОЛЬЗОВАТЕЛЕЙ
id Primary int(11)
name varchar(255)
email Index varchar(255)
password varchar(64)
roles varchar(255)
created_at datetime
Пользовательский
public function setRoles($roles) {
$this->roles = $roles;
}
public function getRoles() {
return $this->roles;
}
security.yml раздел брандмауэров
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
form_login:
login_path: login
check_path: login
pattern: ^/
http_basic: ~
provider: our_db_provider
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
#http_basic: ~
# https://symfony.com/doc/current/security/form_login_setup.html
#form_login: ~
logout:
path: /logout
target: /
Если я изменю функцию getRoles, чтобы вернуть массив, подобный этому
public function getRoles() {
return array('ROLE_USER');
}
В этом случае на странице регистрации отображается ошибка.
The value of type "array" cannot be converted to a valid array key.
Похоже, вы передаете строку для своей роли. Передайте его как массив!
public function __construct($user, $credentials, $providerKey, array $roles = array())
Итак, если роль была Admin
, попробуйте пройти array('admin')
.