0
votes

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.

2
Maybe you have dumped an autoloader earlier ? Try php composer.phar dump-autoload --optimize - Brewal
It doens't seem to be this, the error is persisting - Jeremy L
try to clear the cache first. Then if it is still not working, composer remove, composer require and composer update again. - Brewal
Thank you, that solved ClassNotFoundException. I now have another error that I'll try to solve on my own first haha... Would you mind explaining what was my problem? I don't fully understand - Jeremy L
Clearing the cache often solves issues that you don't understand... Caching is really a complicated thing, so well... I don't know neither ^^ - Brewal

2 Answers

1
votes

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

0
votes

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