2016-11-09 87 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

相关问题