Note that there are some explanatory texts on larger screens.

plurals
  1. POtwig array of objects
    primarykey
    data
    text
    <p>I'm working on a symfony2 project.</p> <p>I send from my controller to twig, an array of arrays of objects.<br> My array is nicely set, and got the values I want.</p> <p>But when I try to access to these datas on twig, I can't...<br> My twig looks like <code>{{ myarray.1.0.getFichier() }}</code></p> <p>But, twig didn't call <code>getFichier</code> method of <code>myarray.1.0</code>.</p> <p>Here is what twig responses to me : <code>Item "getFichier" for "Array" does not exist in CDUserBundle:Prof:edit_session.html.twig at line 74</code></p> <p>Edit : dump(myarray.1.0) shows nothing, dump(myarray) shows nothing. But dump() show a blank page...</p> <p>Edit² : Here is my controller</p> <pre><code>return $this-&gt;render('CDUserBundle:Prof:edit_session.html.twig', array( 'erreur' =&gt; $erreur,'message' =&gt; $message, 'title' =&gt; 'C# | Editer session', 'description' =&gt; 'keywords description', 'sessionInfo' =&gt; $sessionInfo, 'sessionFull' =&gt; $sessionFull, 'documents' =&gt; $documents, 'videos' =&gt; $videos, 'a' =&gt; 'showForm', 'vidName' =&gt; $videos[0]-&gt;getName(), 'vidDMCId'=&gt;$videos[0]-&gt;getDMCId(), 'session' =&gt; $form-&gt;createView(), 'partPath' =&gt; $documents[0]-&gt;getFichier() )); </code></pre> <p>My Array is either $documents either $videos Here is when I create arrays </p> <pre><code> $videos=array(); if($sessionFull[0]['sess_vid_id']!=NULL) { if($em-&gt;getRepository('CD\ConfigBundle\Entity\Video')-&gt;findOneById($sessionFull[0]['sess_vid_id'])) array_push($videos,$em-&gt;getRepository('CD\ConfigBundle\Entity\Video')-&gt;findOneById($sessionFull[0]['sess_vid_id'])); else array_push($videos,new Video()); } else array_push($videos,new Video()); for($i=0;$i&lt;4;$i++) { if($sessionFull[$i]['coursVidId']!=NULL) { $vids=array(); $vidsId=explode(',',$sessionFull[$i]['coursVidId']); foreach($vidsId as $vidId) { if($em-&gt;getRepository('CD\ConfigBundle\Entity\Video')-&gt;findOneById($vidId)) array_push($vids,$em-&gt;getRepository('CD\ConfigBundle\Entity\Video')-&gt;findOneById($vidId)); else array_push($vids,new Video()); } array_push($videos,$vids); } else array_push($videos,array(new Video())); } $documents=array(); if($sessionFull[0]['sess_doc_id']!=NULL) { if($em-&gt;getRepository('CD\ConfigBundle\Entity\Document')-&gt;findOneById($sessionFull[0]['sess_doc_id'])) array_push($documents,$em-&gt;getRepository('CD\ConfigBundle\Entity\Document')-&gt;findOneById($sessionFull[0]['sess_doc_id'])); else array_push(new Document()); } else array_push($documents,new Document()); for($i=0;$i&lt;4;$i++) { if($sessionFull[$i]['coursDocId']!=NULL) { $docs=array(); $docsId=explode(',',$sessionFull[$i]['coursDocId']); foreach($docsId as $docId) { if($em-&gt;getRepository('CD\ConfigBundle\Entity\Document')-&gt;findOneById($docId)) array_push($docs,$em-&gt;getRepository('CD\ConfigBundle\Entity\Document')-&gt;findOneById($docId)); else array_push($docs,new Document()); } array_push($documents,$docs); } else array_push($documents,array(new Document())); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload