我安装了FOS Bundle,如中所述:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md
在用composer安装并设置用户类之后,我总是得到:
[SymfonyComponentDependencyInjectionExceptionServiceNotFoundException]
The service "fos_user.security.login_manager" has a dependency on a non-exi
stent service "security.context".
我检查了路径的存在性,并且fosuserbundle中包含contextterface。。。使用控制台总是会因相同的错误而中止。任何人
我在appKernel中启用了捆绑包(其中安全捆绑包也被激活):
...
new SymfonyBundleSecurityBundleSecurityBundle(),
...
new FOSUserBundleFOSUserBundle(),
...
我在config.yml:中添加了配置
# fos UserBundle config
fos_user:
db_driver: orm
firewall_name: main
user_class: SDDBMainBundleEntityUser
我延长了路线。yml:
# USER AUTH STUFF
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
和安全性。yml:
security:
encoders:
FOSUserBundleModelUserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
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 Bundle开发人员的帮助下找到了解决方案。
如果你有一个类似的问题,通过一些基本的东西:
- FOS Bundle版本是否适合您的Symfony版本
- 安全捆绑包是否正确安装
- 它在appkernel中激活了吗
- 是否有它的配置文件(security.yml)
- 它是否正确地包含在(main)config.yml中
我在第(4)点的包含行中有一个愚蠢的拼写错误。。。
添加:
-{resource:security.yml}到主config.yml中的导入部分,它为我解决了
- 检查服务文件是否存在(SecurityBundle\Resources\config\security.xml)
- 检查是否加载了服务文件(SecurityBundle\DependencyInjection\SecurityExtension.php)