Skip to content

Instantly share code, notes, and snippets.

@smottt
Created March 31, 2012 12:15
Show Gist options
  • Save smottt/2263186 to your computer and use it in GitHub Desktop.
Save smottt/2263186 to your computer and use it in GitHub Desktop.
Quick tip for setting the correct host in your custom symfony2 command.
<?php
namespace Acme\DemoBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class AcmeCommand extends ContainerAwareCommand
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->getContainer()->get('router')->getContext()->setHost('www.example.com');
// ... magic here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment