php - Symfony key array in twig -
i want show information 1 entity.
the entity has information related , use query obtain information.
class playlist { private $id; private $name; private $items; public function __construct() { $this->items = new \doctrine\common\collections\arraycollection(); } public function additem(\publicartel\appbundle\entity\playlistcontent $content) { $content->setplaylist($this); $this->items->add($content); return $this; } public function removeitem(\publicartel\appbundle\entity\playlistcontent $content) { $this->items->removeelement($content); } public function getitems() { return $this->items; } } class playlistcontent { private $content; public function setcontent(\publicartel\appbundle\entity\content $content = null) { $this->content = $content; return $this; } public function getcontent() { return $this->content; } }
// controller:
$playlists = $em->getrepository('publicartelappbundle:playlist')->getallplaylist(); return $this->render('publicartelappbundle:player:calendar.html.twig', array( 'playlists' => $playlists, ));
// query
public function getallplaylist() { $em = $this->getentitymanager(); $dql = 'select p, cnt, plc publicartel\appbundle\entity\playlist p left join p.items cnt left join cnt.content plc'; $query = $this->getentitymanager() ->createquery($dql) ->sethydrationmode(\doctrine\orm\query::hydrate_array); return $query->execute(); }
the consultation seeks elements of content entity, takes left join on ' items' , 'content'.
// twig template
i have sought access element of 2 ways:
{% playlist in playlists.items.content %} <img src="/{{ playlist.path}}"> {% endfor %}
key "items" array keys " 0, 1 " not exist in publicartelappbundle : player : calendar.html.twig @ line 215
{% playlist in playlists %} <img src="/{{ playlist.items.content.path }}"> {% endfor %}
key "content" array keys "0, 1" not exist in publicartelappbundle:player:calendar.html.twig @ line 223
'path' attribute entity 'content' want show.
i guess need loop this:
{% playlistcontent in playlists.items %} {% if playlistcontent.content not null %} <img src="/{{ playlistcontent.content.path }}"> {% endif %} {% endfor %}
edit:
that found:
{% playlist in playlists %} {% playlistcontent in playlist.items %} <img src="/{{ playlistcontent.content.screenshot}}"> <img src="/{{ playlistcontent.content.path}}"> {% endfor %} {% endfor %}
Comments
Post a Comment