我在Symfony 2.6中设置了一个名为ge_lib
的服务,它看起来像下面这样:
ge_lib:
class: GE\RestBundle\Services\GELib
arguments: [@session, @doctrine.orm.entity_manager, @manage_ge_proc]
在GELib.php文件中,我需要使用另一个服务中的函数manage_ge_proc
manage_ge_proc:
class: GE\RestBundle\Services\GEManageProcedure
arguments: [@doctrine.orm.entity_manager, @manage_ge_native_query]
如果我尝试这样使用,它不起作用
$emailInv = $this->get('manage_ge_proc');
$sendStatus = $emailInv->pSendGeneralEmail(.....);
出现错误,说无法找到任何名称为 get 的函数。通常情况下,在任何控制器中都可以使用:$this->get('manage_ge_proc');
。但是在服务中该如何使用呢?
我尝试过使用 $this->getContainer()->get('manage_ge_proc');
,但它没有起作用。
public function __construct(Session $session, EntityManager $emr)
,而不仅仅是变量名称作为参数吗?如果是的话,那么我是否应该将服务的类名GEManageProcedure
作为参数添加进去呢?就像这样:public function __construct(Session $session, EntityManager $emr, GEManageProcedure $manageDeProc)
。 - Manojkumar