title: Displaying Doctrine object in twig
body: <p>I keep getting the error </p>
  
  <pre><code>Method "id" for object "AppBundle\Entity\Domains" does not exist in main\dashboard.html.twig at line 15
  </code></pre>
  
  <p>Here is the code</p>
  
  <p>main\dashboard.html.twig</p>
  
  <pre><code>                    {% for domain in domains %}
                      &lt;p&gt; {{ domain.id }}&lt;/p&gt;
                      &lt;p&gt; {{ domain.domain }}&lt;/p&gt;
                      {% endfor %}
  </code></pre>
  
  <p>Appbundle\Entity\Domains.php</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  
  /**
   * Domains
   * @ORM\Entity
   * @ORM\Table(name="domains")
   */
  class Domains
  {
      /**
       * @ORM\Id
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
       /**
       * @var string
       * @ORM\Column(type="string", length=500)
       */
      protected $domain;
  
  }
  </code></pre>
  
  <p>DashboardController.php</p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Controller;
  
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Request;
  use AppBundle\Entity\Domains;
  
  class DashboardController extends Controller
  {
  /**
   * @Route("/", name="homepage")
   */
  public function indexAction()
  {
      $domain = $this-&gt;getDoctrine()
          -&gt;getRepository('AppBundle:Domains');
  
      $domains = $domain-&gt;findAll();
      foreach ($domains as $domain) {
          dump($domain);
      }
  
      dump($domains);
  
      // replace this example code with whatever you need
      return $this-&gt;render('main/dashboard.html.twig', array('domains' =&gt; $domains));
  }
  
  }
  </code></pre>
  
  <p>Now what I know is $domains is definitely getting the entries. E.g</p>
  
  <pre><code>Array ( [0] =&gt; AppBundle\Entity\Domains Object ( [id:protected] =&gt; 1 [domain:protected] =&gt; hello.com ) [1] =&gt; AppBundle\Entity\Domains Object ( [id:protected] =&gt; 2 [domain:protected] =&gt; stackoverflow.com ) )
  </code></pre>
  
  <p>And that Twig is definitely receiving 'domains', as when I put false variables into Twig it tells it can't find it. If I remove domain.id, then it will error out on domain.domain. </p>
  
  <p>I've tried using both debug and dump within Twig to see the way 'domains' is formatted but I can't seem to get either to work within Symfony.</p>
  
  <p>Can anyone see where I'm going wrong? I think it must be either the way I pass $domains to Twig, or the way I'm trying to access domains within Twig.</p>