2016-11-09 44 views
1

我創建的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

是什麼原因導致該問題?

回答

2

我覺得應該是

arguments: [ "@doctrine.orm.entity_manager" ] 

在Service.yml

+0

完美,它現在有效。謝謝 – hamzo

相關問題