title: Injecting Twig as a service in Symfony2
body: <p>Instead of extending the standard controller, I'd like to inject Twig into one of my classes.</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>namespace Project\SomeBundle\Controller;
  
  use Twig_Environment as Environment;
  
  class SomeController
  {
      private $twig;
  
      public function __construct( Environment $twig )
      {
          $this-&gt;twig    = $twig;
      }
  
      public function indexAction()
      {
          return $this-&gt;twig-&gt;render(
              'SomeBundle::template.html.twig', array()
          );
      }
  }
  </code></pre>
  
  <p>and then in <code>services.yml</code> I have the following:</p>
  
  <pre><code>project.controller.some:
      class: Project\SomeBundle\Controller\SomeController
      arguments: [ @twig ]
  </code></pre>
  
  <p>The error I'm getting is:</p>
  
  <blockquote>
    <p>SomeController::__construct() must be an instance of Twig_Environment, none given</p>
  </blockquote>
  
  <p>But I'm passing in <code>@twig</code> via <code>config</code>. I can't see what I'm doing wrong.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Adding in the correct code - this is what fixed the problem:</p>
  
  <pre><code>// in `routing.yml` refer to the service you defined in `services.yml` 
  project.controller.some
      project_website_home:
          pattern:  /
          defaults: { _controller: project.controller.some:index }
  </code></pre>