问题
I installed the FOS Bundle like mentioned in: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md
After installation with composer and setting up the user class i always get:
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
The service "fos_user.security.login_manager" has a dependency on a non-exi
stent service "security.context".
I checked the existence of the path and there is the contextinterface that is included in the fosuserbundle... Using the console always aborts with the same error. Anyone?
I enabled the bundle in appKernel (where the security bundle also is activated):
...
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
...
new FOS\UserBundle\FOSUserBundle(),
...
I added the config to the config.yml:
# fos UserBundle config
fos_user:
db_driver: orm
firewall_name: main
user_class: SDDB\MainBundle\Entity\User
I extended the routing.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
and the security.yml:
security:
encoders:
FOS\UserBundle\Model\UserInterface: 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 }
回答1:
Ok i found the solution with help of a developer of FOS Bundle.
If you have a simmilar problem go through some basic stuff:
- Is the FOS Bundle version fitting for your Symfony version?
- Is security bundle proper installed?
- Is it activated in the appkernel?
- Is there a configuration file for it (security.yml)?
- Is it inlcuded properly in the (main)config.yml?
I had a dumb typo in the include line at point (4)...
回答2:
Add :
- { resource: security.yml } to the import section in the main config.yml, it solved the problem for me
回答3:
- Check whether the service file exists (SecurityBundle\Resources\config\security.xml)
- Check whether the service file is loaded (SecurityBundle\DependencyInjection\SecurityExtension.php)
来源:https://stackoverflow.com/questions/18126393/symfony-2-3-fosuserbundle-does-not-find-security-context