2017-08-11 76 views
2

装入类“FOSUserBundle”(在Windows 10使用WampServer)ClassNotFoundException的:试图从命名空间“FOS UserBundle”

我跟着以超过Symfony的安装索纳塔用户捆绑的官方文档。

我收到以下错误消息

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

AppKernel.php

<?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'); 
    } 
} 

config.yml

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) 

的routing.yml

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 

当我到了2.5步与运行

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

开始我得到

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


正如意见中的要求:composer.json的自动加载部分

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

您是否安装它/与作曲家加入了吗? –

+0

是的,正如指南中提到的那样。 – TTT

+0

清除缓存,更新FOS用户群也检查这里[同样的问题(https://stackoverflow.com/questions/30863601/classnotfoundexception-symfony-userbundle) –

回答

3

在composer.json

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

比更新作曲:

composer update 

,如果这不工作,以便尝试通过该命令来固定束:

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

扩展基本用户FosUser:

class Myusers extends BaseUser 
{ 
} 

在config.yml

fos_user: 
    user_class: MyBundle\Entity\Myusers 
+0

试图更改自动加载。没有成功。你能解释一下这个改变应该做什么吗? 尝试第二种解决方案:仍然致命错误:在第32行的AppKernel.php中找不到类'FOS \ UserBundle \ FOSUserBundle'。 – TTT

+0

它将这些包保存在src目录中!你更新了作曲家? –

+0

是的,我跑了“作曲家更新” – TTT