41918

ClassNotFoundException: Attempted to load class “FOSUserBundle” from namespace “FOS\\UserBundle”

(Using WampServer on Windows 10.)

I followed the official documentation in order to install Sonata User Bundle over Symfony.

I get the following error message

(1/1) ClassNotFoundException Attempted to load class "FOSUserBundle" from namespace "FOS\UserBundle". Did you forget a "use" statement for another namespace?

<strong>AppKernel.php</strong>

<?php use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppKernel extends Kernel { public function registerBundles() { $bundles = [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new AppBundle\AppBundle(), new Sonata\CoreBundle\SonataCoreBundle(), //Added following https://sonata-project.org/bundles/admin/3-x/doc/getting_started/installation.html new Sonata\BlockBundle\SonataBlockBundle(), new Knp\Bundle\MenuBundle\KnpMenuBundle(), new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(), new Sonata\AdminBundle\SonataAdminBundle(), //Added following https://sonata-project.org/bundles/easy-extends/2-x/doc/reference/installation.html new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(), //Added following https://sonata-project.org/bundles/user/3-x/doc/reference/installation.html new FOS\UserBundle\FOSUserBundle(), new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'), ]; if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); if ('dev' === $this->getEnvironment()) { $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle(); } } return $bundles; } public function getRootDir() { return __DIR__; } public function getCacheDir() { return dirname(__DIR__).'/var/cache/'.$this->getEnvironment(); } public function getLogDir() { return dirname(__DIR__).'/var/logs'; } public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); } }

<strong>config.yml</strong>

imports: - { resource: parameters.yml } - { resource: security.yml } - { resource: services.yml } # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: locale: en framework: #esi: ~ #translator: { fallbacks: ['%locale%'] } secret: '%secret%' router: resource: '%kernel.project_dir%/app/config/routing.yml' strict_requirements: ~ form: ~ csrf_protection: ~ validation: { enable_annotations: true } #serializer: { enable_annotations: true } templating: engines: ['twig'] default_locale: '%locale%' trusted_hosts: ~ session: # https://symfony.com/doc/current/reference/configuration/framework.html#handler-id handler_id: session.handler.native_file save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%' fragments: ~ http_method_override: true assets: ~ php_errors: log: true # Twig Configuration twig: debug: '%kernel.debug%' strict_variables: '%kernel.debug%' # Doctrine Configuration doctrine: dbal: driver: pdo_mysql host: '%database_host%' port: '%database_port%' dbname: '%database_name%' user: '%database_user%' password: '%database_password%' charset: UTF8 # if using pdo_sqlite as your database driver: # 1. add the path in parameters.yml # e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite' # 2. Uncomment database_path in parameters.yml.dist # 3. Uncomment next line: #path: '%database_path%' types: json: Sonata\Doctrine\Types\JsonType orm: auto_generate_proxy_classes: '%kernel.debug%' naming_strategy: doctrine.orm.naming_strategy.underscore auto_mapping: true entity_managers: default: mappings: ApplicationSonataUserBundle: ~ SonataUserBundle: ~ FOSUserBundle: ~ # If SonataUserBundle extends it # Swiftmailer Configuration swiftmailer: transport: '%mailer_transport%' host: '%mailer_host%' username: '%mailer_user%' password: '%mailer_password%' spool: { type: memory } #Sonata sonata_core: form_type: horizontal sonata_user: security_acl: true manager_type: orm # can be orm or mongodb sonata_block: default_contexts: [cms] blocks: # enable the SonataAdminBundle block sonata.admin.block.admin_list: contexts: [admin] #... sonata.user.block.menu: # used to display the menu in profile pages sonata.user.block.account: # used to display menu option (login option) sonata.block.service.text: # used to if you plan to use Sonata user routes #FOSUser fos_user: db_driver: orm # can be orm or odm firewall_name: main user_class: Sonata\UserBundle\Entity\BaseUser group: group_class: Sonata\UserBundle\Entity\BaseGroup group_manager: sonata.user.orm.group_manager # If you're using doctrine orm (use sonata.user.mongodb.group_manager for mongodb) service: user_manager: sonata.user.orm.user_manager # If you're using doctrine orm (use sonata.user.mongodb.user_manager for mongodb)

<strong>routing.yml</strong>

login_view: path: '/login/' defaults: { _controller: AppBundle:Login:view } singlesingon_view: path: '/authentication/singlesignon/' defaults: { _controller: AppBundle:AuthenticationSingleSignOn:view } singlesingout_view: path: '/authentication/singlesignout/' defaults: { _controller: AppBundle:AuthenticationSingleSignOut:view } app: resource: '@AppBundle/Controller/' type: annotation admin_area: resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml" prefix: /admin sonata_user_admin_security: resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml' prefix: /admin sonata_user_admin_resetting: resource: '@SonataUserBundle/Resources/config/routing/admin_resetting.xml' prefix: /admin/resetting

When I reach step 2.5 which starts with running

php bin/console sonata:easy-extends:generate SonataUserBundle -d src

I get

Fatal error: Class 'FOS\UserBundle\FOSUserBundle' not found.

<hr>

As requested in comments: autoload section of composer.json

"autoload": { "psr-4": { "AppBundle\\": "src/AppBundle" }, "classmap": [ "app/AppKernel.php", "app/AppCache.php" ] },

Answer1:

In composer.json

"autoload": { "psr-0": { "": "src/", "Application": "app/" } },

than Update Composer :

composer update

if this dont work so try to fix the bundle by this command :

php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle

Extend base user FosUser :

class Myusers extends BaseUser { }

In config.yml

fos_user: user_class: MyBundle\Entity\Myusers

Recommend

  • Symfony 2 production app unable to find any Twig template
  • Google gantt chart shows wrong year
  • Passing values between SWFs
  • How to add JNI hooks to one jar generated by Spring Boot
  • Migration solution for singletons in an OSGI environment
  • Tcl/tk version in Python installation
  • .net Core Webpack Publish from VS 2017 failing
  • Autoloading classes when not in same directory as zend library
  • Tomcat JDBC MySQL ClassNotFoundException
  • How to use an anonymous class instance in another generate bytecode class
  • Why does adding a reference to jasmine.js break my ReSharper test?
  • pass a base path to a swf loaded at runtime
  • Twig_Error_Syntax for “Unknown filter” with a Twig filter in Timber
  • Spring AOP Logging Interceptor and JAXB issue
  • ClassNotFoundException: Attempted to load class “FOSUserBundle” from namespace “FOS\\UserBundle”
  • How to prevent JBoss inter web application classpath?
  • Angular2-mdl and webpack
  • How to change permission of mapped volume in kubernetes/Docker
  • How can I change config file path in Codeigniter?
  • Unable to import a React Component in my Mocha test
  • Android - What should I use to get data from remote db?
  • Pipeline fails due to `hijack: Backend error`
  • AJAX problem in Internet Explorer
  • firebase unauth with google doesn't allow change of user
  • How to update docker-compose on Docker for Windows?
  • Files in gitignore
  • System call time out?
  • jhipster run embedded jar with prod profile - issue with liquibase
  • Sybase Error Implicit Conversion from datatype 'VARCHAR' to 'INT' not allowed
  • In Java, how can I construct a File from a resource?
  • Most efficient way to move table rows from one table to another
  • Servlet stops working on Tomcat server after some hits or time
  • JBoss External Properties Files in Classpath
  • Paperclip, set path outside of rails root folder
  • Launch Runnable Jar from Web Start
  • In LanguageTool, how do you create a dictionary and use it for spell checking?
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Circular dependency while pushing http interceptor
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • UserPrincipal.Current returns apppool on IIS