用户 "App\Entity\User" 没有用户提供商
There is no user provider for user "App\Entity\User"
我正在尝试将 FosUserBundle 与 Symfony 3.4.7 一起使用,但出现以下错误:
There is no user provider for user "App\Entity\User".
此错误发生在以下代码的最后一行:
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$controller->get('security.token_storage')->setToken($token);
$controller->get('session')->set('_security_main',serialize($token));
这是 security.yaml 文件的内容:
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
App\Entity\User: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
class: App\Entity\User
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
这是 fos_user.yaml 文件:
fos_user:
db_driver: orm
firewall_name: main
use_listener: false
user_class: App\Entity\User
from_email:
address: lannuzel+bot@gmail.com #"%mailer_user%"
sender_name: bot #"%mailer_user%"
composer.json:
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.0.8",
"ext-iconv": "*",
"friendsofsymfony/user-bundle": "dev-master",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "^3.4",
"symfony/console": "^3.4",
"symfony/expression-language": "^3.4",
"symfony/flex": "^1.0",
"symfony/form": "^3.4",
"symfony/framework-bundle": "^3.4",
"symfony/lts": "^3",
"symfony/monolog-bundle": "^3.1",
"symfony/orm-pack": "*",
"symfony/process": "^3.4",
"symfony/security-bundle": "^3.4",
"symfony/serializer-pack": "*",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/templating": "^3.4",
"symfony/twig-bundle": "^3.4",
"symfony/validator": "^3.4",
"symfony/web-link": "^3.4",
"symfony/webpack-encore-pack": "*",
"symfony/yaml": "^3.4"
},
"require-dev": {
"symfony/browser-kit": "^3.4",
"symfony/css-selector": "^3.4",
"symfony/debug-pack": "*",
"symfony/dotenv": "^3.4",
"symfony/maker-bundle": "^1.0",
"symfony/phpunit-bridge": "^3.4",
"symfony/profiler-pack": "*",
"symfony/web-server-bundle": "^3.4"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\Tests\": "tests/"
}
},
"replace": {
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"id": "01C9QBD7ETMR057HZKBE94RA2A",
"allow-contrib": false
},
"symfony.id": "01C9QAREG207VK8TQR3XP0R4DV"
}
}
我错过了什么?
在 providers
下缩进 fos_userbundle
,因为现在它不被识别为提供程序的参数。 YAML 对它的空格非常挑剔
我的错误,我创建了一个 config/security.yaml
文件,而已经有一个 config/packages/security.yaml
文件。
将所有内容放入后者解决了问题。
我正在尝试将 FosUserBundle 与 Symfony 3.4.7 一起使用,但出现以下错误:
There is no user provider for user "App\Entity\User".
此错误发生在以下代码的最后一行:
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$controller->get('security.token_storage')->setToken($token);
$controller->get('session')->set('_security_main',serialize($token));
这是 security.yaml 文件的内容:
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
App\Entity\User: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
class: App\Entity\User
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
这是 fos_user.yaml 文件:
fos_user:
db_driver: orm
firewall_name: main
use_listener: false
user_class: App\Entity\User
from_email:
address: lannuzel+bot@gmail.com #"%mailer_user%"
sender_name: bot #"%mailer_user%"
composer.json:
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.0.8",
"ext-iconv": "*",
"friendsofsymfony/user-bundle": "dev-master",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "^3.4",
"symfony/console": "^3.4",
"symfony/expression-language": "^3.4",
"symfony/flex": "^1.0",
"symfony/form": "^3.4",
"symfony/framework-bundle": "^3.4",
"symfony/lts": "^3",
"symfony/monolog-bundle": "^3.1",
"symfony/orm-pack": "*",
"symfony/process": "^3.4",
"symfony/security-bundle": "^3.4",
"symfony/serializer-pack": "*",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/templating": "^3.4",
"symfony/twig-bundle": "^3.4",
"symfony/validator": "^3.4",
"symfony/web-link": "^3.4",
"symfony/webpack-encore-pack": "*",
"symfony/yaml": "^3.4"
},
"require-dev": {
"symfony/browser-kit": "^3.4",
"symfony/css-selector": "^3.4",
"symfony/debug-pack": "*",
"symfony/dotenv": "^3.4",
"symfony/maker-bundle": "^1.0",
"symfony/phpunit-bridge": "^3.4",
"symfony/profiler-pack": "*",
"symfony/web-server-bundle": "^3.4"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\Tests\": "tests/"
}
},
"replace": {
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"id": "01C9QBD7ETMR057HZKBE94RA2A",
"allow-contrib": false
},
"symfony.id": "01C9QAREG207VK8TQR3XP0R4DV"
}
}
我错过了什么?
在 providers
下缩进 fos_userbundle
,因为现在它不被识别为提供程序的参数。 YAML 对它的空格非常挑剔
我的错误,我创建了一个 config/security.yaml
文件,而已经有一个 config/packages/security.yaml
文件。
将所有内容放入后者解决了问题。