Symfony2 FOSUserBundle - 您请求了一个不存在的服务“security.user_checker”
我使用 Symfony 2 和 FOSUserBundle。我可以登录、注销和查看个人资料。
问题:当我转到“/register”时,填写表单并按 Enter 键,我收到以下错误:
您请求了不存在的服务“security.user_checker”。 500 内部服务器错误 - ServiceNotFoundException
似乎我已经做了一些额外的配置,但我找不到任何相关信息。
config.yml 的一部分:
fos_user:
db_driver: orm
firewall_name: fos_user
user_class: Blogger\BlogBundle\Entity\User
security.yml:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
fos_user:
id: fos_user.user_manager
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
fos_user:
pattern: ^/
provider: fos_user
form_login:
check_path: /login_check
login_path: /login
logout:
path: /logout
target: /
anonymous: ~
access_control:
- { path: /secured/admin, roles: ROLE_ADMIN }
- { path: ^/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
更新
堆栈跟踪:
I use Symfony 2 and the FOSUserBundle. I can login, logout and view Profile.
Problem: When i go to "/register", fill out the form and press enter i get the following error:
You have requested a non-existent service "security.user_checker".
500 Internal Server Error - ServiceNotFoundException
It seems that I have do to some additional configuration or so, but I can't find anything about it.
Part of config.yml:
fos_user:
db_driver: orm
firewall_name: fos_user
user_class: Blogger\BlogBundle\Entity\User
security.yml:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
fos_user:
id: fos_user.user_manager
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
fos_user:
pattern: ^/
provider: fos_user
form_login:
check_path: /login_check
login_path: /login
logout:
path: /logout
target: /
anonymous: ~
access_control:
- { path: /secured/admin, roles: ROLE_ADMIN }
- { path: ^/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
UPDATE
Stack trace:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保为 FOSUserBundle 指定版本。存储库头与 Symfony 头对齐,而不是 2.0.9。
Make sure you specify a version for FOSUserBundle. The repository head is aligned with Symfony head, not 2.0.9.
如果您要更新 FOSUserBundle(或任何与此相关的捆绑包),您需要确保模仿 FOSUserBundle 中对您覆盖的任何文件所做的更改。
在我的特定情况下,在 RegistrationController FOSUserBundle 中,在authenticateUser 方法中将值从 security.user_checker 更改为 fos_user.user_checker,因此我在控制器中进行了相同的更改。
每次更新供应商时,您都需要确保您在捆绑包中覆盖的文件(控制器、服务等)不依赖于已删除的服务类或方法。
If you're updating FOSUserBundle (or any bundle for that matter) you need to make sure you mimic changes made in the FOSUserBundle to any files you overwrite.
In my particular case, in the RegistrationController FOSUserBundle changed a value from security.user_checker to fos_user.user_checker in the authenticateUser method, so I made the same change in my controller.
Every time you do an update of the vendors, you need to make sure files (controllers, services etc) you're overwriting in your bundle are not depending on a service class or method that has been removed.
您注册服务正确吗?
或者也许您忘记了为此服务添加路由?
Do you register services right ?
Or maybe You forgot add a routing for this service ?