2016-03-04 122 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中的域的方式。

回答