我創建的symfony服務如下所述:Symfony2: get Doctrine in a generic PHP class呼叫一個成員函數getRepository()上串
Service.yml
app.lib.helpers:
class: AppBundle\Lib\Helpers
arguments: [doctrine.orm.entity_manager]
類助手
class Helpers
{
protected $em;
public function __construct($entityManager)
{
$this->em = $entityManager;
}
public function checkStatuses()
{
$orderId = $this->em->getRepository('AppBundle:Orders')->findAll();
}
}
在控制器動作
$helper = $this->get('app.lib.helpers');
$helper->checkStatuses();
但即時獲取錯誤:
Error: Call to a member function getRepository() on string
是什麼原因導致該問題?
完美,它現在有效。謝謝 – hamzo