Symfony2 class_parents() Class does not exist erro

2019-08-01 05:15发布

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条回答
【Aperson】
2楼-- · 2019-08-01 05:32

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.

查看更多
登录 后发表回答