command是运行在控制台中;若是想要生成绝对URL;因为在控制台中没法获取请求上下文;因此须要配置请求上下文app
####全局配置this
# app/config/parameters.yml parameters: router.request_context.host: example.org router.request_context.scheme: https router.request_context.base_url: my/path
####在各个命令中设置url
$context = $this->getContainer()->get('router')->getContext(); $context->setHost('example.com'); $context->setScheme('https'); $context->setBaseUrl('/my/path'); //eg: ttps://example.com/my/path/test/command 最终生成的URL $this->getContainer()->get('router')->generate("test_command", [], true);