Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 0.72 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can i access repository functions in twig template in symfony2
  2. {% for category in categories %}
  3.     --{{ category.name }}--
  4.       {% for product in getProducts(category.id,location) %}
  5.      --{{ product.name }}--
  6.     {% endfor %}
  7.  {% endfor %}
  8.        
  9. {% render '@MyBundle:Product:list' with {category: category.id} %}
  10.        
  11. class CategoryManager
  12. {
  13.     public function loadCategoriesProductsForLocation($location)
  14.     {
  15.         $qb = $this->em->->createQueryBuilder();
  16.  
  17.         $qb->addSelect('category');
  18.         $qb->addSelect('product');
  19.  
  20.         $qb->from('MyBundleBundle:Category','category');
  21.  
  22.         $qb->leftJoin('category.products','product',
  23.             ExprJoin::WITH, $qb->expr()->eq('product.location', $location));