Symfony 2 - Twig templates - Entity function results -
i looking best solution how send value returned 1 of entity function's in symfony2 twig template. 
the problem connecting getting file url file uploaded according "how handle file uploads doctrine" manual (http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html). following last example ("using id filename").
in controller getting 1 of documents entity.
$document = $this->getdoctrine()->getrepository('appbundle:documents')->find($id);   and provide entity details twig template:
return $this->render('appbundle:documents:details.html.twig', array('document' => $document));   however in template need link file generated getabsolutepath() function.
 public function getabsolutepath()     {         return null === $this->link             ? null             : $this->getuploadrootdir().'/'.$this->id.'.'.$this->link;     }   i may use in controller following code:
return $this->render('appbundle:documents:details.html.twig', array('document' => $document, 'link' => $document->getabsolutepath()));   but solution not seems tidy me, sending $document twig. practical solution?
its simple. in twig template can do:
{{ document.getabsolutepath() }}      
Comments
Post a Comment