【问题标题】:ClassNotFoundException: Attempted to load class "DoctrineFixturesBundle"ClassNotFoundException:试图加载类“DoctrineFixturesBundle”
【发布时间】:2014-03-13 12:00:47
【问题描述】:

我的所有 url 网站都有这个返回 symfony 错误:
"ClassNotFoundException: Attempted to load class "DoctrineFixturesBundle" from namespace "Doctrine\Bundle\FixturesBundle" in C:\dev\Apache2.4.6\htdocs\MySite\app\AppKernel.php line 23. 你需要“使用“它来自另一个命名空间?

当我修改 config.yml(部分教义 orm)以解决其他问题时出现此错误,但它没有解决。确实支持我在此文件中的更改并重新运行我的网站,但现在没有任何运行正常。我随时随地都有这个错误。

我在这里复制我的代码,但只是为了回答简单的问题:
- 你是否在 AppKernel.php 中添加了这一行 : $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(); ? 回答:是的
- 你有安装固定装置包吗? 回复:是
- 你有安装/更新和自我更新作曲家吗? 回复:是
- 你在 DB 中有负载装置吗? 响应:是的(它运行完美)
- 你有清理缓存吗? 响应:是

我所有的灯具引擎都在这产生错误之前正确运行。

AppKernel.php

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
        $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    }

composer.json

    "require": {
    "php": ">=5.3.3",
    "symfony/symfony": "~2.4",
    "doctrine/orm": "2.4.2",
    "doctrine/doctrine-bundle": "~1.2",
    "twig/extensions": "~1.0",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~2.3",
    "sensio/framework-extra-bundle": "~3.0",
    "sensio/generator-bundle": "~2.3",
    "incenteev/composer-parameter-handler": "~2.0",
    "doctrine/doctrine-fixtures-bundle": "dev-master"
},

config.yml

doctrine:
dbal:
    driver:   "%database_driver%"
    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, add the path in parameters.yml
    # e.g. database_path: "%kernel.root_dir%/data/data.db3"
    # path:     "%database_path%"

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true

感谢您的宝贵帮助

【问题讨论】:

    标签: symfony doctrine-orm


    【解决方案1】:

    非常奇怪的行为,因为它是自动和单独解决的。 大量缓存后:清除,手动删除缓存,AppKernel.php中的注释/注释行解决此问题。

    但是一个新的开始......

    现在这是我无法运行的开发工具栏 symfony。

    我认为为这个新问题创建一个新主题,不要与此混为一谈。

    【讨论】:

    • 我也是,我也遇到了这个问题,我认为这是由于将代码从 windows 复制/psting 到 unix 平台(例如 Ubuntu)引起的。对我来说,每次我将代码从 windows 复制到 unix 时,都会出现此错误。
    • 我不知道您的评论是否详细说明了我的实际问题的原因,但我已经看到了与您所说的 linux 和 windows 同时工作的错误。
    【解决方案2】:

    我在

    上遇到了同样奇怪的错误
    new Application\Extended\SonataMediaBundle\ExtendedSonataMediaBundle()
    

    在我的情况下,在我修复 composer.json 文件并运行 composer update 后,它又恢复了工作。正确地说,我第一次启动“composer update”时没有修复 composer.json 并且错误没有消失,所以“composer update”本身不是解决方案,关键是 composer.json 文件修复。

    这更奇怪,因为它是 错误 修复 - 我删除了 psr-0 自动加载定义中的斜线,所以有:

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

    我明白了:

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

    只有一个斜线! 这是错误的修复,因为作曲家建议不要使用空命名空间

    $ composer validate 
    ./composer.json is valid, but with a few warnings
    See https://getcomposer.org/doc/04-schema.md for details on the schema
    Defining autoload.psr-0 with an empty namespace prefix is a bad idea for performance
    

    注 1:它在前几天使用该斜线,今天停止工作,很奇怪。项目在两个工作状态之间的时间保持不变!

    注意2:composer.json文件的初始(in-box)状态是没有斜线的,我在两周前添加了它以压制composer的不满。

    【讨论】:

    • 我不知道您的回复是否解决了我的问题,但我认为这是有用且感兴趣的回复。感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 2018-03-26
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 1970-01-01
    • 2019-09-08
    相关资源
    最近更新 更多