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.
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] 삭제
몇 마디 만하겠습니다