【发布时间】:2014-01-20 03:39:44
【问题描述】:
所以我尝试关注symfony2's tutorial on doctrine 建立我自己的网站,并在他们的Product 之后为我的User 实体建模。
另外,在有人将此标记为重复之前,我已经尝试了许多其他问题中给出的解决方案,但没有运气:
- 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;
}
?>
现在,我正在运行命令:
$ php app/console doctrine:generate:entities MySite/MyBundle/Entity/User
生成访问器方法。但是,当我这样做时,我得到了错误:
[Doctrine\ORM\Mapping\MappingException]
Class "MySite\MyBundle\Entity\User" is not a valid entity or mapped super class.
【问题讨论】:
-
当您使用 php app/console 学说:generate:entities - 这意味着您从数据库生成实体。但是您手动创建实体并尝试覆盖它。运行 php app/console dictionary:mapping:info 它会告诉你是否在教义中的映射结构有问题
-
感谢您的回复。那么symfony教程错了吗?在“生成获取器和设置器”部分中,它说“教义:生成:实体”是生成获取器和设置器。当我运行教义:映射:信息时,我得到: [异常] 根据当前配置,您没有任何映射的 Doctrine ORM 实体。如果你有实体或映射文件,你应该检查你的映射配置是否有错误。
-
我不是想从数据库中生成它们,而是从 PHP 文件中生成它们。无论如何,我想通了,我的 config.yml 中缺少
auto_mapping: true行;现在一切正常。 -
好。如果用户user2443357给出正确答案,请将答案设置为“正确”