ClassNotFoundException:尝试从命名空间“FOS\UserBundle”加载类“FOSUserBundle”

2023-12-24

(在 Windows 10 上使用 WampServer。)

我按照官方文档通过 Symfony 安装 Sonata User Bundle。

我收到以下错误消息

(1/1) ClassNotFoundException 尝试加载类“FOSUserBundle” 来自命名空间“FOS\UserBundle”。您是否忘记了“使用”声明 另一个命名空间?

应用程序内核.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');
    }
}

配置.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)

路由.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

I get

致命错误:未找到类“FOS\UserBundle\FOSUserBundle”。


按照评论中的要求:composer.json 的自动加载部分

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

在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 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ClassNotFoundException:尝试从命名空间“FOS\UserBundle”加载类“FOSUserBundle” 的相关文章

  • PHP 如何判断用户是否按下了 Enter 键或 Submit 按钮?

    我遇到的问题是我在一个表单中有多个提交输入 每个提交输入都有不同的值 我更愿意将它们保留为提交 Whenever the user presses Enter it is as though the topmost submit input
  • 如何检查PHP变量是否包含非数字?

    我只是想知道检查 PHP 变量中是否有非数字的方法以及它是否也检测字符之间的空格 需要确保我的表单字段中没有添加任何奇怪的内容 提前致谢 如果您的意思是您只想要一个包含数字的值 那么您可以使用ctype digit http php net
  • FPDI/FPDF:水印和打印多页

    我修改了这个堆栈问题 当用户尝试下载文件时在 pdf 文件上应用水印 https stackoverflow com questions 3983432 applying watermarks on pdf files when users
  • 蛋糕控制台 2.2.1:烘焙错误

    运行 MAMP 的 OSX 机器 CakePHP 2 2 1 已正确安装和配置 这意味着当我浏览到 Index php 文件时 所有绿色条都显示出来 我已经完成了博客教程 并且正在开发我的第二个应用程序 其中脚手架已启动并运行 现在我第一次
  • 是否可以使用 PHP 重定向发送 POST 数据?

    更新 这不是重复的如何使用 PHP 发送 POST 请求 https stackoverflow com questions 5647461 how do i send a post request with php 那里的解决方案对我不起
  • 如何在原则 2 迁移中删除外键

    我想在原则 2 迁移中删除外键 但没有 dropForeignKeyConstraint 有谁知道怎么丢掉吗 public function down Schema schema table schema gt getTable table
  • 从 .phar 存档中提取文件

    对于 Phar 文件 我完全错过了一些东西 我正在安装一个需要 phpunit pdepend 和其他依赖项的项目 我将它们作为 phar 文件获取 但是 我无法使用命令行工具 php 命令 从中提取文件 我用谷歌搜索了这个问题 但没有发现
  • 交换关联数组中的两个项目

    Example arr array apple gt sweet grapefruit gt bitter pear gt tasty banana gt yellow 我想调换一下柚子和梨的位置 这样数组就变成了 arr array ap
  • PHP 在输入流中使用 fwrite 和 fread

    我正在寻找将 PHP 输入流的内容写入磁盘的最有效方法 而不使用授予 PHP 脚本的大量内存 例如 如果可以上传的最大文件大小为 1 GB 但 PHP 只有 32 MB 内存 define MAX FILE LEN 1073741824 1
  • MySQL 追加字符串

    How can I append a string to the end of an existing table value Let s say I have the table below And let s say that Mari
  • 覆盖控制器 Symfony 3.4/4.0

    我目前正在尝试覆盖 FOSUserBundle 中的控制器 在新的文档中 https symfony com doc 3 4 bundles override html https symfony com doc 3 4 bundles o
  • 通过 $_SESSION 从一个脚本发送到另一个脚本期间数据丢失

    我正在尝试将一个充满属性的对象从一个 PHP 发送到另一个 PHP SESSION object obj where obj是一个用 foreach 循环指定的对象 foreach array of objects as obj SESSI
  • 跟踪用户何时点击浏览器上的后退按钮

    是否可以检测用户何时单击浏览器的后退按钮 我有一个 Ajax 应用程序 如果我可以检测到用户何时单击后退按钮 我可以显示适当的数据 任何使用 PHP JavaScript 的解决方案都是优选的 任何语言的解决方案都可以 只需要我可以翻译成
  • Symfony 4:添加 Twig_Extension_StringLoader

    在我的 Symfony 4 项目中 我有一个包含 HTML 的变量 我尝试使用 Twig 显示该变量 我想使用template from string 功能但我必须添加Twig Extension StringLoader到 Twig 环境
  • php,统计字符并删除超过140个字符的内容

    我需要一个 PHP 函数来计算短语的字符数 如果短语长度超过 140 个字符 则此函数应删除所有其他字符并在短语末尾添加三个点 例如我们有 message I am what I am and you are what you are et
  • 使用正则表达式提取两个短语之间的所有单词[重复]

    这个问题在这里已经有答案了 我正在尝试使用以下正则表达式提取两个短语之间的所有单词 b item W w W 0 2 1 one W w W 0 3 business b b item W w W 0 2 3 three W w W 0 3
  • 为什么 Composer 降级了我的包?

    php composer phar update这样做了 删除了 2 3 0 软件包并安装了整个 2 2 5 Zend Framework php composer phar update Loading composer reposito
  • Magento - 自定义支付模块

    这是一个非常普遍的问题 但这里是 我正在尝试在 Magento 中创建一个自定义支付模块 我创建了一个 常规 模块 可以连接到 Magento 事件 观察者模型 但是我如何告诉 Magento 将模块视为支付模块 以便它显示在管理后端和结账
  • post php mysql 的拆分关键字

    我有一个表存储帖子 ID 它的标签如下 Post id Tags 1 keyword1 keyword2 keyword3 我想循环遍历该表中的每一行并执行以下操作 将关键字1 关键字2 关键字3放入新表中 word id word val
  • 无法显示 Laravel 欢迎页面

    我的服务器位于 DigitalOcean 云上 我正在使用 Ubuntu 和 Apache Web 服务器 我的家用计算机运行的是 Windows 7 我使用 putty 作为终端 遵循所有指示https laracasts com ser

随机推荐

  • 将 HTML 导出到 Excel 而不丢失格式

    我有一个生成报告的 asp net 页面 无论好坏 整个事情都是使用嵌套表生成的 我能够将页面导出到 Excel 但是我丢失了所有格式 无法设置列宽等 有办法处理这个问题吗 我愿意添加 html 方面所需的任何愚蠢的 MS Office 特
  • 在 SQL 查询中执行正则表达式(替换)

    将所有 lt 替换为的最佳方法是什么 lt 在给定的数据库列中 基本上执行s lt lt gi Notes 必须工作于微软SQL服务器 http en wikipedia org wiki Microsoft SQL Server SQL
  • Laravel - 未定义的偏移量 0 - collection.php

    我正在编写一个网络应用程序 后端是一个基于 Laravel 4 的 RESTFul 应用程序 我在使用特定控制器时遇到问题 BedsController php class BedsController extends BaseContro
  • RPY2:导入程序因 .Renviron 失败

    这是使用时应该发生的事情rpy2 robjects packages importr对于基础 R 包 例如stats gt gt gt from rpy2 robjects packages import importr gt gt gt
  • 量角器 - 描述未定义

    我正在使用 Protractor js 进行测试 当我尝试使用运行测试用例时 量角器 e2e main test spec js 我的conf js An example configuration file exports config
  • DatePicker 不更新 Android 中的 Textview

    当选择某个日期的日期选择器时 我试图更新文本视图 但它的textview 没有更新 我正在使用两个日期选择器来更新两个不同的文本视图 这是我更新 TextView 的代码 public class SearchingActivity ext
  • wxPython CheckListBox 与 HTML

    我正在使用 wxPython 创建一个 GUI 应用程序 现在我正在使用 wx CheckListBox 来显示带有复选框的选项 但我希望使用 HTML 来格式化 CheckListBox 中的文本 解决这个问题的最佳方法是什么 Repla
  • 如何滚动重启一群杂种集群

    任何人都知道一种通过 Capistrano 以 滚动 方式重新启动杂种集群的好方法 例如一次一个杂种 如果每个人都有一点等待时间 让杂种也能加载 Rails 应用程序 那就太好了 我已经做了一些搜索 但没有找到太多 所以在我自己深入研究 m
  • 我可以使用 boost 库来执行跨平台应用程序吗?

    boost c 库中是否有任何 WinAPI WinExec 模拟 我需要从我的程序运行可执行文件 并将参数传递给它 我应该为此使用任何其他跨平台库 还是自己处理我的程序编译的操作系统 重要的 请参阅末尾的 POSIX 系统更新
  • 为什么我会收到有关此代码示例的警告?什么才是正确的呢?

    我正在学习一些 C 并且正在阅读scanf from 本教程 http www tutorialspoint com c standard library c function scanf htm其中包含以下代码块 include
  • WCF NetTcpBinding 缓冲与流性能问题

    我编写了一个 WCF 服务 该服务应该使用 Streamed TransferMode 转换任何大小的文件NetTcpBinding and System IO Stream object 在运行性能测试时 我发现了明显的性能问题 然后我决
  • 如何设置带空格的环境变量?

    我需要使用批处理文件设置环境变量的值 我为此编写了脚本 echo off set value Hello world setx M srijani srijani value 它给出了错误 ERROR Invalid syntax Defa
  • 重命名字典键

    有没有一种方法可以重命名字典键 而无需将其值重新分配给新名称并删除旧名称键 并且不迭代 dict 键 值 的情况下OrderedDict https docs python org 3 library collections html co
  • JPA更新多对多删除记录

    我在两个实体之间有 ManyToMany 关系 当我在拥有方执行更新时 JPA 似乎从我的数据库中删除了所有链接记录并重新插入它们 对我来说这是一个问题 因为我有一个在删除记录之前触发的 MySQL 触发器 关于如何解决这个问题有什么想法吗
  • .NET 进程间通信的最佳选择是什么? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 我应该使用命名管道还是 NET Remoting 与计算机上正在运行的进程进行通信 WCF是最好的选择 它支持许多不同的传输机制 https l
  • 是否可以在 c/c++ 中的 double 类型(8 字节)变量中存储 8 个字符(每个字符 1 字节)?

    我正在将一些旧版 Fortran77 代码迁移到 C C 在Fortran77代码中 如果从文件中读入8个字符 则可以将它们存储在real 8类型的变量中 没有问题 是否可以在 C 或 C 中做类似的事情 如果是这样 我该怎么做 我无法在互
  • 标签指向 PHP 动态生成的图像?

    是否可以将图像重定向到动态生成的图像 使用 PHP 我有一个动态创建的图像 它有一个扩展名 PHP 显然 并且该服务器不在我的控制之下 所以我想将 somename jpg 在我的服务器上 重定向到 remoteserver dynamic
  • Rails 4 - 当前布局的名称?

    我找到了许多关于 Rails 3 的资源 但没有找到关于 Rails 4 的资源 为了保持干燥 我们有一个定义一些元标记的方法 我想将布局包含在title param app controllers application controll
  • 在 Google bigquery 中转换数据 - 提取文本、将其拆分为多列并旋转数据

    我在大查询中有一些博客数据 我需要对其进行转换以使其更易于使用和查询 数据如下 我想提取并转换数据在 Results 之后的大括号内 蓝色 数据的形式为 d PQ KL d 结果数组中可以有 1 20 多个条目 我只对前 16 个条目感兴趣
  • ClassNotFoundException:尝试从命名空间“FOS\UserBundle”加载类“FOSUserBundle”

    在 Windows 10 上使用 WampServer 我按照官方文档通过 Symfony 安装 Sonata User Bundle 我收到以下错误消息 1 1 ClassNotFoundException 尝试加载类 FOSUserBu