![](/img/trans.png)
[英]Symfony2 - “Warning: class_parents(): Class Ambience does not exist and could not be loaded in ”
[英]Symfony2 class_parents() Class does not exist error
我正在嘗試從 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
。 我已經針對此類錯誤檢查了 SO 上的其他答案,但沒有一個與我的具體問題相符。
Symfony2 使用自動加載來加載帶有類的文件。 當您請求uow
類時,它會查找 uow.php 文件。 文件名在 linux 服務器上區分大小寫,因此 uow.php 和 Uow.php 是不同的文件。
您需要在$entity
上添加某種地圖或使用ucfirst
函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.