【问题标题】:Symfony2 - "Warning: class_parents(): Class Ambience does not exist and could not be loaded in "Symfony2 - “警告:class_parents():Class Ambience 不存在,无法加载”
【发布时间】:2014-06-30 13:43:21
【问题描述】:

我正在尝试使用 yml 创建实体,但出现以下错误:

[ErrorException]

  Warning: class_parents(): Class Ambience does not exist and could not be loaded in C:\wamp\www\demo\vendor\gedmo-doctrine-extensions\lib\Gedmo\Mapping\ExtensionMetadataFactory.php line 80

我在 FooBundle/Resources/config/doctrine/metadata/orm 中创建了一个名为 Entities.UserTestDelete.dcm.yml 的文件

文件内容:

Entities\UserTestDelete:
  type: entity
  table: users
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    name:
      type: string
      length: 50

然后我执行了以下命令:

php app/console doctrine:mapping:import "DemoFooBundle" yml

然后我得到了错误。知道为什么会有问题吗?

【问题讨论】:

    标签: php symfony doctrine-orm


    【解决方案1】:

    刚刚遇到同样的问题...并设法解决...

    异常类的 __contruct 上的 var_dump($this),在我的例子中:

    • Symfony\Component\Debug\Exception\ContextErrorException

    得到了 $message->$trace,这导致我:

    • vendor/sylius/resource-bundle/EventListener/LoadORMMetadataSubscriber.php
    • 调用函数“class_parents”
    • 在函数“setAssociationMappings”中

    所以快速解决方法是简单地注释掉订阅的事件:

    /**
     * @return array
     */
    public function getSubscribedEvents()
    {
    //    return array(
    //        'loadClassMetadata',
    //    );
    }
    

    现在再次运行“应用程序/控制台原则:映射:导入”时......不会再有错误......

    如果需要,在再次启用/取消注释订阅的事件之前运行 mapping:convert 和 generate:entities 命令...

    如果您不使用 Sylius,请尝试对异常类进行 var_dump'ing ... 很有可能您也遇到了一些 Eventlistner 干扰 Doctrine 的 Import 命令...

    祝你好运!

    【讨论】:

      【解决方案2】:

      更新
      您的第一个错误是 创建了 yml 文件。正如the cookbook 中所解释的,doctrine:mapping:import 命令实际上生成 文件。放弃你的,运行命令,让教义自己生成文件。
      之后你要做的是生成实际的实体类:

      php app/console doctrine:mapping:convert annotation ./src
      php app/console doctrine:generate:entities DemoFooBundle
      

      如果表本身还不存在,那么您可以使用最后 2 个命令生成实体,然后运行

      php app/console doctrine:schema:update --force
      

      让教义为您创建表格。


      快速浏览一下说明书告诉我,不应引用捆绑名称,并且您可能希望将 --force 标志传递给教义:映射:导入命令。
      It's in the reverse-engineering bit

      php app/console doctrine:mapping:import --force DemoFooBundle yml
      

      这是 Symfony2 cookbook 给出的示例,只是改为采用 yml,而不是 xml 格式。

      错误信息也可能与表名有关:

      table: users
      

      调用实体的位置

      class Users
      {}
      

      possible related question

      【讨论】:

      • 即使在更改命令并将表名更改为另一个名称后,它也会给出完全相同的错误。
      • @GeorgiAngelov:抱歉,没有仔细阅读问题,已更新
      • 我放弃了手动创建的 yml 文件并运行了命令。它给了我完全相同的错误...是否需要为我设置任何特定的配置文件才能使用教义?
      • @GeorgiAngelov:尝试清除学说缓存(app/console doctrine:cache:clear-metadataclear-queryclear-result
      • 我运行了所有三个命令,但它们没有返回任何结果(没有什么要清除的)。之后我运行命令,错误仍然存​​在。
      猜你喜欢
      • 2012-11-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2017-07-29
      • 2011-09-25
      • 1970-01-01
      • 2023-03-07
      相关资源
      最近更新 更多