在尝试说明书中的 Symfony2 示例时映射异常


Mapping Exception when trying out the Symfony2 example from the cookbook

我刚刚开始学习Symfony2,我正在遵循Symfony网站上的"The Cookbook"中的示例。

尝试有关从数据库(实体提供程序)加载用户的章节中的代码(链接到该章节)时,出现以下错误:

MappingException: Class Acme'UserBundle'Entity'User is not a valid entity or mapped super class.

。并且无法发现我做错了。我确实认为我遵循了本章中提供的所有步骤。

感谢您的任何帮助,

在逐步修改整个代码时,我终于发现了问题。

我忘了在AppKernel.php中注册UserBundle。

我有同样的问题。我查看了symfony+映射错误,但该解决方案对我不起作用。然后我发现,Michi解决方案 https://stackoverflow.com/a/10935672/2910183

所以,这就是我所做的:

  1. AppKernel.php中注册捆绑包:

    new Acme'UserBundle'AcmeUserBundle(),

  2. 创建此捆绑包(它只是 FOS''UserBundle''FOSUserBundle 的副本)并另存为src/Acme/UserBundle/AcmeUserBundle.php


    <?php
    namespace Acme'UserBundle;
    use Symfony'Component'HttpKernel'Bundle'Bundle;
    use Symfony'Component'DependencyInjection'ContainerBuilder;
    use Doctrine'Bundle'DoctrineBundle'DependencyInjection'Compiler'DoctrineOrmMappingsPass;
    use Doctrine'Bundle'MongoDBBundle'DependencyInjection'Compiler'DoctrineMongoDBMappingsPass;
    use Doctrine'Bundle'CouchDBBundle'DependencyInjection'Compiler'DoctrineCouchDBMappingsPass;
    class AcmeUserBundle extends Bundle { }