Symfony2 class_parents() Class does not exist error

微笑、不失礼 提交于 2020-01-05 07:54:25

问题


I am trying to get data from a table with Doctrine 2 in a Symfony2 application. Code that works on my development machine throws an error when deployed to a production server. Here is one of my controllers.

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);
}

The above code works on a linux server in my local development machine. One of the entities, is as follows.

<?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
}

I have default settings for doctrine on config.yml and this is the error.

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

Running php app/console doctrine:mapping:info returns OK for all the entities. I've checked other answers on SO for this type of error and none match my specific problem.


回答1:


Symfony2 uses autoloading to load files with classes. When you ask for uow class it looks for uow.php file. File names are case sensitive on a linux server , so uow.php and Uow.php are different files.

You'll need to add some sort of map or use ucfirst function on $entity.



来源:https://stackoverflow.com/questions/13413487/symfony2-class-parents-class-does-not-exist-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!