ClassNotFoundException Symfony UserBundle

余生颓废 提交于 2020-01-25 20:22:27

问题


I'm developping a website on Symfony2, I want to intergrate FOSUserBundle. I am using Doctrine ORM User class. I've followed the installation steps but I got this error:

ClassNotFoundException in AppKernel.php line 21:
Attempted to load class "FOSUserBundle" from namespace "FOS\UserBundle".
Did you forget a "use" statement for another namespace?

AppKernel.php:

    public function registerBundles()
{
    $bundles = array(
        ...
        new FOS\UserBundle\FOSUserBundle(),
    );

It looks correctly placed: FOSUserBundle.php is located in \vendor\friendsofsymfony\userbundle

And the namespace is correct I think: namespace FOS\UserBundle;

Other files:

#config.yml

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: REMERA\PlatformBundle\Entity\User

#routing.yml

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

#security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    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: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
            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 }

I've been trying to solve this for hours, answers on other similar questions don't resolve my error. Am I missing something? Thanks in advance.


回答1:


How this was solved:

try to clear the cache first. Then if it is still not working, composer remove, composer require and composer update again. – Brewal




回答2:


When you try to clear cache but its not getting cleared you should use --no-warmup option, this will make sure that you cache is re-generated and cache is not warmed up only. I think this can help you:

php app/console cache:clear --env=prod --no-warmup

or

php app/console cache:clear --env=dev --no-warmup


来源:https://stackoverflow.com/questions/30863601/classnotfoundexception-symfony-userbundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!