我有一个控制器作为服务,我想从我的命令
中调用它这是我的配置
#service.yml
parameters:
dg_app.controller.glossaries.class: dg\AppBundle\Controller\GlossaryController
services:
dg.glossary.controller:
synchronized: true
class: "%dg_app.controller.glossaries.class%"
calls:
- [ setContainer, [ @service_container ]]
#MyCommand.php
$request = $this->getContainer()->get('request');
$categories = $this->getContainer()->get('dg.glossary.controller')->setGlossaryAction($request);
#GlossaryController
/**
* @Route("set_glossary/{type}",name="set_glossary_watches")
* @Template("xxxBundle:Glossary:glossary.html.twig")
*/
public function setGlossaryAction(Request $request) {
...
}
使用此配置我有此错误
[Symfony\Component\DependencyInjection\Exception\InactiveScopeException]
You cannot create a service ("request") of an inactive scope ("request").
如何使用不同的参数(类型参数)调用控制器?
答案 0 :(得分:0)
添加你的commande
$this->getContainer()->enterScope('request');
$this->getContainer()->set('request', new Request(), 'request');