2016-03-04 99 views
0

显示学说对象我不断收到错误在树枝

Method "id" for object "AppBundle\Entity\Domains" does not exist in main\dashboard.html.twig at line 15 

这里是代码

主要\ dashboard.html.twig

    {% for domain in domains %} 
        <p> {{ domain.id }}</p> 
        <p> {{ domain.domain }}</p> 
        {% endfor %} 

的appbundle \实体\ Domains.php

<?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; 

} 

DashboardControll er.php

<?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->getDoctrine() 
     ->getRepository('AppBundle:Domains'); 

    $domains = $domain->findAll(); 
    foreach ($domains as $domain) { 
     dump($domain); 
    } 

    dump($domains); 

    // replace this example code with whatever you need 
    return $this->render('main/dashboard.html.twig', array('domains' => $domains)); 
} 

} 

现在我知道的是$域是肯定得到的条目。 E.g

Array ([0] => AppBundle\Entity\Domains Object ([id:protected] => 1 [domain:protected] => hello.com) [1] => AppBundle\Entity\Domains Object ([id:protected] => 2 [domain:protected] => stackoverflow.com)) 

这嫩枝肯定是接受“域”,因为当我把假的变量纳入嫩枝它告诉它不能找到它。如果我删除了domain.id,那么它会在domain.domain上出错。

我试过在Twig中同时使用调试和转储来查看'域'格式化的方式,但我似乎无法在Symfony中工作。

任何人都可以看到我要去哪里错了吗?我认为它必须是我向Twig传递$域的方式,或者我试图访问Twig中的域的方式。

回答