如何设置用户通过ContainerAwareCommand提供的DIC参数?

时间:2017-05-11 19:38:40

标签: symfony

是否可以在ContainerAwareCommand中设置Container参数,如$this->getContainer()->setParameter('host', $host);

因为代码如下:

class ServerCommand extends ContainerAwareCommand
{
    protected function configure()
    {
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $helper = $this->getHelper('question');
        $question1 = new Question('Provide a hostname: ', 'localhost');
        $host = $helper->ask($input, $output, $question1);

        $this->getContainer()->setParameter('host', $host);

给我DependencyInjection \ Exception \ LogicException:

  

无法在冻结的ParameterBag上调用set()。

0 个答案:

没有答案