类 ..Entity\User 不是有效的实体或映射的超类
当我尝试清除缓存时出现此错误(例如):
[Doctrine\ORM\Mapping \MappingException] 类 Aib\PlatformBundle\Entity\User 不是有效实体或映射的超级 类。
这是User.php:
<?php
// src/Aib/PlatformBundle/Entity/User.php
namespace Aib\PlatformBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
这是User.php 存储的地方:
javier@javier:~/programacion/aib/src/Aib/PlatformBundle/Entity$ ls User.php UserRepository.php
这是AppKernel.php:
public function registerBundles()
{
$bundles = array(
...
new Aib\PlatformBundle\AibPlatformBundle(),
...
);
sf 2.0.4
I'm getting this error when I try to clear the cache (for example):
[Doctrine\ORM\Mapping \MappingException] Class
Aib\PlatformBundle\Entity\User is not a valid entity or mapped super
class.
This is User.php:
<?php
// src/Aib/PlatformBundle/Entity/User.php
namespace Aib\PlatformBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
And this is the place where User.php is stored:
javier@javier:~/programacion/aib/src/Aib/PlatformBundle/Entity$ ls
User.php UserRepository.php
This is the AppKernel.php:
public function registerBundles()
{
$bundles = array(
...
new Aib\PlatformBundle\AibPlatformBundle(),
...
);
sf 2.0.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
就我而言,我的类定义中缺少
* @ORM\Entity
。In my case I was missing
* @ORM\Entity
in my class definition.我在实施 FOS UserBundle 时有完全相同的经历,并发现我能够通过删除 MyBundle\Resources\config\doctrine 文件夹来解决该问题。
我不完全理解原因(新手),但认为问题是由于以麻烦的方向构建数据库内容的结果,即从条令实体和通过逆向工程一些表。
I had the exact same experience with my implementation of the FOS UserBundle and found I was able to resolve the issue by removing the MyBundle\Resources\config\doctrine folder.
I dont fully understand the cause (newbie) but think the issue is a result of having database content built in bother directions, ie from doctrine entities and by reverse engineering some tables.
我遇到了同样的问题,结果是 app/config/config.yml
它需要默认包的定义,如下所示 NameBundle,然后它工作正常
I had the same problem and it turned out to be the app/config/config.yml
It needed the defintion of the default bundle as below NameBundle, then it worked fine
就我而言,通过将服务器缓存从eAccelerator更改为APC解决了问题。
显然,eAccelerator 会从文件中删除所有会破坏注释的注释。
In my case the problem was solved by changing my servers cache from eAccelerator to APC.
Apparently eAccelerator strips all the comments from files which breaks your annotations.
我遇到了同样的错误,但这是因为我没有包含 Sonata 应用程序:
尝试以下操作:
在 AppKernel.php 中添加一行
I had the same error, but this was because I wasn't including the Sonata Application:
try this:
add a line to your AppKernel.php
如果继承自映射类,则可以在实体的注释中添加@ORM\SuperMappedClass。
您可以在 这篇文章。
If you inherited from mapped class, you can add @ORM\SuperMappedClass in entity's annotation.
You can read most information in this article.