【问题标题】:Symfony2 class_parents() Class does not exist errorSymfony2 class_parents() 类不存在错误
【发布时间】:2012-11-04 23:53:12
【问题描述】:

我正在尝试从 Symfony2 应用程序中使用 Doctrine 2 的表中获取数据。在我的开发机器上运行的代码在部署到生产服务器时会引发错误。这是我的一个控制器。

public function listEntitiesAction($entity, Request $request)
{       
    $repository = $this->getDoctrine()->getRepository('AALCOInventoryBundle:' . $entity);
    $metadata = $this->getDoctrine()->getEntityManager()->getClassMetadata('AALCOInventoryBundle:' . $entity);
    $dataTable = new Datatable( $request->query->all(), $repository, $metadata, $this->getDoctrine()->getEntityManager());  
    $dataTable->makeSearch();   
    $view = $this->view($dataTable->getSearchResults(), 200)
            ->setFormat('json');
    return $this->get('fos_rest.view_handler')->handle($view);
}

上面的代码在我的本地开发机器上的 linux 服务器上运行。其中一个实体,如下所示。

<?php
namespace AALCO\InventoryBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
 * AALCO\InventoryBundle\Entity\Uom
 *
 * @ORM\Table(name="uoms")
 * @ORM\Entity
 */
class Uom
{
    // entity stuff
}

我在 config.yml 上有教义的默认设置,这是错误。

request: ErrorException: Warning: class_parents() [<a href='function.class-parents'>function.class-parents</a>]: Class AALCO\InventoryBundle\Entity\uom does not exist and could not be loaded in 
/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php line 40 (uncaught exception) at 
/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php line 40

运行php app/console doctrine:mapping:info 为所有实体返回OK。我已经检查了关于此类错误的其他答案,但没有一个符合我的具体问题。

【问题讨论】:

    标签: php symfony orm doctrine


    【解决方案1】:

    Symfony2 使用自动加载来加载带有类的文件。当您要求 uow 类时,它会查找 uow.php 文件。 linux服务器上的文件名区分大小写,所以uow.php和uow.php是不同的文件。

    您需要添加某种地图或在$entity 上使用ucfirst 函数。

    【讨论】:

    • 谢谢。在您的帮助下解决了问题。但是,我还有一个包含实体“Branch.php”、“User.php”等的不同捆绑包,并且我能够从它们那里获取数据而不会出现此错误。不知道为什么会这样。
    猜你喜欢
    • 1970-01-01
    • 2012-07-20
    • 2012-07-26
    • 2014-09-21
    • 2014-05-26
    • 2014-05-22
    • 1970-01-01
    • 2013-05-08
    • 1970-01-01
    相关资源
    最近更新 更多