title: Redirect from a Service in Symfony2
body: <p>I have a service that looks up data for a page, but if that data isn't found, should redirect to the homepage.  For the life of me, I can't figure out how to do this in Sf2.  There are so many different ways to work with services and router, but none seem to work.</p>
  
  <pre><code>namespace Acme\SomeBundle\Services;
  
  use Acme\SomeBundle\Entity\Node;
  use \Doctrine\ORM\EntityManager;
  use \Symfony\Component\HttpKernel\Event\GetResponseEvent;
  use \Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  use \Symfony\Bundle\FrameworkBundle\Routing\Router;
  use \Symfony\Component\Routing\Generator\UrlGenerator;
  use Symfony\Component\HttpFoundation\RedirectResponse;
  
  class NodeFinder
  {
  
      private $em;
      private $router;
  
      public function __construct(EntityManager $em, Router $router)
      {
  
          $this-&gt;em = $em;
          $this-&gt;router = $router;
  
      }
  
      public function getNode($slug)
      {
  
          $node = $this-&gt;em-&gt;getRepository('SomeBundle:Node')-&gt;findOneBy(array('slug' =&gt; $slug));
  
          if (!$node) { //if no node found
  
                  return  $this-&gt;router-&gt;redirect('homepage', array(), true);
          }
  }
  </code></pre>