Twig rendering of a mapped objects

Bastien

I am spinning my wheel to render an object in a twig template. I have 3 entities user >> customer >> account each one mapped to the next with a bi-directionnal one-to-many relationship. I want to fetch all accounts for a specific customer using this controller

//...
public function showAction($customerref)
{
 $customer=$this->getDoctrine()->getRepository('AcmeCustomerBundle:Customer')
->find($customerref);
$accounts = $customer->getAccounts();
return $this->render('mytemplate.html.twig', array('accounts'=>$accounts));
}

I try to retrieve the information related to the "accounts" object in twig using

{% for account in accounts %}
{{ account.id }}
{{ account.number}}
{% endfor %}

I get the error "Notice: undefined index:customer". I cannot make sense of this error. When does the "customer" index need to be defined? This is what I have when I dump the "accounts" object.

PersistentCollection {#1061 ▼
  -snapshot: []
  -owner: Customer {#1060 ▼
    -id: 11
    -name: "nameofthecustomer"
    +user: User {#947 ▼
      -id: 1
      -username: "tom"
      #customers: PersistentCollection {#968 ▶}
    }
    #accounts: PersistentCollection {#1061}
  }
  -association: array:15 [ …15]
  -em: EntityManager {#151 …10}
  -backRefFieldName: "customer"
  -typeClass: ClassMetadata {#948 …}
  -isDirty: false
  -initialized: false
  -coll: ArrayCollection {#1062 ▼
    -_elements: []
  }
}

Could anyone give me some guidance on why I get this error? I have used a similar code many times (e.g. to display all customer for one specific user and it worked perfectly well)? Thanks.

Bastien

I left some typos indeed (i just corrected them). I happen to have found the solution. I had issues with the way my entities were mapped. This is where I found some useful tips http://obtao.com/blog/symfony2-issues-you-do-not-understand/

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Backup mapped drive paths

분류에서Dev

Check if a drive is mapped and active

분류에서Dev

twig 안에 html 'with'twig 포함

분류에서Dev

Gedit warning: GtkScrolledWindow is mapped but visible child GtkScrollbar is not mapped

분류에서Dev

hibernate mapping verify if an object is mapped

분류에서Dev

Twig javascript path with id

분류에서Dev

Disable formatting in Twig

분류에서Dev

Twig, subtract 2 dates

분류에서Dev

Client side rendering and skipping server rendering approach?

분류에서Dev

Twig 및 PHPMailer 작업

분류에서Dev

Symfony: Twig values remain the same

분류에서Dev

Loop over two arrays in Twig

분류에서Dev

Getting value from a twig to a controller

분류에서Dev

Symfony security and twig Render funcion

분류에서Dev

extend Twig to define assets url

분류에서Dev

Scala's hierarchy mapped to Java's

분류에서Dev

How to map DispatcherServlet on /foo/* while Tapestry is mapped on /*

분류에서Dev

Adding to mapped collection in NHibernate - transaction concern

분류에서Dev

How to show currently mapped drives in PowerShell?

분류에서Dev

Upload CSV File then Mapped to Tables in Database

분류에서Dev

SVG images not rendering in Safari

분류에서Dev

Conditionally Rendering in React Native

분류에서Dev

Set controller for template rendering

분류에서Dev

JSF Trinidad Rendering not working

분류에서Dev

Ejs - templating data is not rendering

분류에서Dev

Drop location rendering with swing

분류에서Dev

HDR rendering on Android

분류에서Dev

STL rendering with threejs

분류에서Dev

Lists Not Rendering Correctly in IE