Symfony2: How to set the correct host for routing in console command

Symfony2: How to set the correct host for routing in console command

Quick tip for setting the correct host in your custom symfony2 command.

  1. $this->getContainer()->get(‘router’)->getContext()->setHost(‘www.example.com’);

This will set your host correctly for routing and it will no longer default to ‘localhost’.

A bit longer version: