如何解决类不是有效的实体或映射的超类? [英] How to fix class is not a valid entity or mapped super class?

查看:42
本文介绍了如何解决类不是有效的实体或映射的超类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试针对我的 symfony2的教程自己的网站,并根据他们的 Product 产品对我的 User 实体进行建模.

So I'm trying to follow symfony2's tutorial on doctrine for my own website and modeling my User entity after their Product one.

此外,在任何人将其标记为重复之前,我已经尝试了许多其他问题中给出的解决方案,但是没有运气:

Also, before anyone marks this a duplicate, I have already tried the solutions given in numerous other questions with no luck:

  • Not a valid entity or mapped super class
  • Doctrine class is not a valid entity or mapped super class
  • Symfony/Doctrine: Class is not a valid entity or mapped super class
  • symfony2 is not a valid entity or mapped super class
  • Symfony/Doctrine: Class is not a valid entity or mapped super class
  • "Class XXX is not a valid entity or mapped super class" after moving the class in the filesystem

列表继续

我有我的实体课:

<?php
    namespace MySite\MyBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;

    /**
     * @ORM\Entity
     * @ORM\Table(name="user")
     */
    class User
    {
        /**
         * @ORM\Column(type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;

        /**
         * @ORM\Column(type="string", length=100)
         */
        protected $name;

        /**
         * @ORM\Column(type="string", length=64)
         */
        protected $password;
    }
?>

现在,我正在运行命令:

Now, I'm running the command:

$ php app/console doctrine:generate:entities MySite/MyBundle/Entity/User

生成访问器方法.但是,当我这样做时,我得到了错误:

to generate the accessor methods. However, when I do this, I get the error:

[Doctrine\ORM\Mapping\MappingException]
Class "MySite\MyBundle\Entity\User" is not a valid entity or mapped super class.

推荐答案

好吧,我自己弄清楚了.我的问题是我的config.yml错误.我在config.yml中缺少 auto_mapping:true 行.

Ok, I figured it out myself. My problem is that my config.yml was wrong. I was missing the auto_mapping: true line in my config.yml.

doctrine:
    # (dbal stuff here)

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

添加完之后,使用 php应用程序/控制台学说:generate:entities MySite/MyBundle/Entity/User 行自动生成一切正常

After adding that, everything auto-generates fine with the php app/console doctrine:generate:entities MySite/MyBundle/Entity/User line

这篇关于如何解决类不是有效的实体或映射的超类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆