symfony2不是有效的实体或映射的超类 [英] symfony2 is not a valid entity or mapped super class

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

问题描述

我有一个symfony2应用程序,在我的本地pc与ubuntu,并且运行良好,但在CentOS和Cpanel服务器不工作,我得到这个错误:


类Propa\PageBundle\Entity\Page不是有效的实体或映射的
超级类。



CRITICAL - Doctrine\ORM\Mapping\MappingException:Class
Propa\PageBundle\Entity\Page不是有效的实体或映射的超级
类。 (未捕获的例外)
/home/estudi83/domains/serverprova.com.es/propa/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php
第216行

我证明:

  $ page = $ EM-> getRepository( 'PropaPageBundle:页') - > findOneBy(阵列( 'CODI'=> '0001')); 

并获取此错误:未知实体名称空间别名PropaPageBundle code>



而且我证明:

  $ page = $ EM-> getRepository( 'Propa\PageBundle\Entity\Page') - > findOneBy(阵列( 'CODI'=> '0001')); 

并获得相同的错误:类Propa \PageBundle\Entity\\ \\ Page不是有效的实体或映射的超类。



这是实体:

 <?php 
命名空间Propa\PageBundle\Entity;

使用Doctrine\ORM\Mapping作为ORM;
使用Symfony\Component\Validator\Constraints作为Assert;
使用Doctrine\Common\Collections\ArrayCollection;
使用Vich\UploaderBundle\Mapping\Annotation为Vich;
使用Propa \PageBundle\Util;
使用Gedmo\Mapping\Annotation作为Gedmo;




/ **
* @ ORM\Entity(repositoryClass =Propa\PageBundle\Repository\PageRepository)
* @ Gedmo\TranslationEntity(class =Propa \PageBundle\Entity\Translation\PageTranslation)
* @ ORM\HasLifecycleCallbacks
* @ Vich\Uploadable
* /

类页面{

/ **
* @ ORM\Id
* @ ORM\Column(type =整数)
* @ ORM\GeneratedValue
* /
protected $ id;

我证明了:

  auto_mapping:true 

  auto_mapping:false 
映射:
PageBundle:〜

但总是获得相同的错误。



我可以做什么?



更新:解决的问题是在eAccelerator与symfony2注释,我卸载了eAccelerator并安装了APC,工作正常!

解决方案

最后,它可能是缓存优化器的问题。如果您正在使用eAccelerator,那么您将会遇到问题,可能是使用Doctrine。原因是eAccelerator从代码中删除注释!您可以尝试使用理论表现良好的APC。



阅读 apc vs eaccelerator vs xcache






看看

  http://you.site.name/config.php 

它显示了应该出现的要求,使您的应用程序正常工作。



AND



请公开您的网页实体类。






可能有很多原因导致此错误,您的问题是已经在这里询问了SO XXX类不是有效的实体或映射的超类在文件系统中移动课程



https://github.com/symfony/symfony/issues/4554






  $页= $ EM-> getRepository( 'PageBundle:页') - > findOneBy(阵列( 'CODI'=> '0001')); 

将其更改为

  $ page = $ em-> getRepository('PropaPageBundle:Page') - > findOneBy(array('codi'=>'0001')); 

  $ page = $ em-> getRepository('Propa\PageBundle\Entity\Page') - > findOneBy(array('codi'=>'0001')); 

,看看它是否有效。


I have a symfony2 app, in my local pc with ubuntu and works well, but in server with CentOS and Cpanel not works, I obtained this error:

Class "Propa\PageBundle\Entity\Page" is not a valid entity or mapped super class.

CRITICAL - Doctrine\ORM\Mapping\MappingException: Class "Propa\PageBundle\Entity\Page" is not a valid entity or mapped super class. (uncaught exception) at /home/estudi83/domains/serverprova.com.es/propa/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php line 216

I prove:

$page=$em->getRepository('PropaPageBundle:Page')->findOneBy(array('codi'=>'0001'));

And obtain this error: Unknown Entity namespace alias 'PropaPageBundle'.

And I prove:

 $page=$em->getRepository('Propa\PageBundle\Entity\Page')->findOneBy(array('codi'=>'0001'));

And obtain same error: Class "Propa\PageBundle\Entity\Page" is not a valid entity or mapped super class.

This is the Entity:

<?php
namespace Propa\PageBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Propa\PageBundle\Util;
use Gedmo\Mapping\Annotation as Gedmo;




/**
 * @ORM\Entity(repositoryClass="Propa\PageBundle\Repository\PageRepository")
 * @Gedmo\TranslationEntity(class="Propa\PageBundle\Entity\Translation\PageTranslation")
 * @ORM\HasLifecycleCallbacks
 * @Vich\Uploadable
 */

class Page {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    protected $id;

I had proved:

auto_mapping: true

and

auto_mapping: false
mappings:
    PageBundle: ~

But always obtain the same error.

What Can I do?

UPDATE: Resolved the problem was in eAccelerator with symfony2 annotations, I'm uninstalled eAccelerator and installed APC and works fine!!

解决方案

Finally, it may be a cache optimizer issue. If you are using eAccelerator, then you will have problems, probably with Doctrine. The reason is eAccelerator removes annotations from the code! You can try APC which performs well with doctrine.

Read apc vs eaccelerator vs xcache


Have a look at

http://you.site.name/config.php

It shows you the requirements that should be present to make your application work.

AND

please expose your page entity class.


There may be many reasons for this error and your question was already asked here on SO "Class XXX is not a valid entity or mapped super class" after moving the class in the filesystem

https://github.com/symfony/symfony/issues/4554


$page=$em->getRepository('PageBundle:Page')->findOneBy(array('codi'=>'0001'));

change it to

 $page=$em->getRepository('PropaPageBundle:Page')->findOneBy(array('codi'=>'0001'));

or

 $page=$em->getRepository('Propa\PageBundle\Entity\Page')->findOneBy(array('codi'=>'0001'));

and see if it works.

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

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