0

I'm working on a symfony2 project.

I send from my controller to twig, an array of arrays of objects.
My array is nicely set, and got the values I want.

But when I try to access to these datas on twig, I can't...
My twig looks like {{ myarray.1.0.getFichier() }}

But, twig didn't call getFichier method of myarray.1.0.

Here is what twig responses to me : Item "getFichier" for "Array" does not exist in CDUserBundle:Prof:edit_session.html.twig at line 74

Edit : dump(myarray.1.0) shows nothing, dump(myarray) shows nothing. But dump() show a blank page...

Edit² : Here is my controller

return $this->render('CDUserBundle:Prof:edit_session.html.twig', array(
            'erreur' => $erreur,'message' => $message,
            'title' => 'C# | Editer session',
            'description' => 'keywords description',
            'sessionInfo' => $sessionInfo,
            'sessionFull' => $sessionFull,
            'documents' => $documents,
            'videos' => $videos,
            'a' => 'showForm',
            'vidName' => $videos[0]->getName(),
            'vidDMCId'=>$videos[0]->getDMCId(),
            'session' => $form->createView(),
            'partPath' => $documents[0]->getFichier()
        ));

My Array is either $documents either $videos Here is when I create arrays

  $videos=array();
    if($sessionFull[0]['sess_vid_id']!=NULL) {
        if($em->getRepository('CD\ConfigBundle\Entity\Video')->findOneById($sessionFull[0]['sess_vid_id']))
            array_push($videos,$em->getRepository('CD\ConfigBundle\Entity\Video')->findOneById($sessionFull[0]['sess_vid_id']));
        else
            array_push($videos,new Video());
        }
    else
        array_push($videos,new Video());
    for($i=0;$i<4;$i++) {
        if($sessionFull[$i]['coursVidId']!=NULL) {
            $vids=array();
            $vidsId=explode(',',$sessionFull[$i]['coursVidId']);
            foreach($vidsId as $vidId) {
                if($em->getRepository('CD\ConfigBundle\Entity\Video')->findOneById($vidId))
                    array_push($vids,$em->getRepository('CD\ConfigBundle\Entity\Video')->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->getRepository('CD\ConfigBundle\Entity\Document')->findOneById($sessionFull[0]['sess_doc_id']))
            array_push($documents,$em->getRepository('CD\ConfigBundle\Entity\Document')->findOneById($sessionFull[0]['sess_doc_id']));
        else
            array_push(new Document());
    }
    else
        array_push($documents,new Document());
    for($i=0;$i<4;$i++) {
        if($sessionFull[$i]['coursDocId']!=NULL) {
            $docs=array();
            $docsId=explode(',',$sessionFull[$i]['coursDocId']);
            foreach($docsId as $docId) {
                if($em->getRepository('CD\ConfigBundle\Entity\Document')->findOneById($docId))
                    array_push($docs,$em->getRepository('CD\ConfigBundle\Entity\Document')->findOneById($docId));
                else
                    array_push($docs,new Document());
            }
            array_push($documents,$docs);
        }
        else
            array_push($documents,array(new Document()));
    }
10
  • If you use the dump function on myarray.1.0 what do you get? Is your method public? Commented Feb 22, 2013 at 17:32
  • Dump shows nothing. My method come from Doctrine Entity, so yes I think. Maybe my object have been empty set ( new Document() ) Commented Feb 22, 2013 at 17:39
  • What if you use {{ dump(myarray) }} then? Can you post the result in your question? Commented Feb 22, 2013 at 17:41
  • Post your Twig template pls. Commented Feb 22, 2013 at 17:46
  • 1
    what about using {{ document[1][0].fichier }} instead? Commented Feb 22, 2013 at 22:07

1 Answer 1

0

Use {{ myarray.1.0.Fichier }} directly

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.