Symfony Tree就像Twig中的结构

时间:2015-11-18 10:34:03

标签: symfony twig

我有3个实体

  1. 子组
  2. 产品
  3. 我通过加入这些表来获取数据

    Group-SubGroup(OneToMany)Product-SubGroup(ManyToMany)

    数据:

    +---------------+------------+----------+
    |     Group     |  Subgroup  | Product  |
    +---------------+------------+----------+
    | Food          | Fruits     | Apple    |
    | Food          | Fruits     | Orange   |
    | Food          | Vegetables | Brinjal  |
    | Food          | Vegetables | Onion    |
    | Food          | Vegetables | Potato   |
    | Food          | Vegetables | Zucchini |
    | Clothes       | Men        | Jeans    |
    | Clothes       | Men        | Shirts   |
    | Clothes       | Women      | Jeans    |
    | Clothes       | Women      | Skirt    |
    +---------------+------------+----------+
    

    我想要实现的是使用树枝的树状结构

    Group     
      Subgroup   
            Product  
    Group     
      Subgroup  
            Product  
            Product  
    Group     
      Subgroup  
           Product  
           Product  
           Product  
    

    任何想法我怎样才能在树枝上实现这一目标{i here但是我不明白...... ??

1 个答案:

答案 0 :(得分:0)

嗯,我想你可以这样运行它(如果我做对了)

{% for group in groups %}
    {% for subgroup in group.subgroups %}
        {% for product in subgroup.products %}
            // display your products
        {% endfor %}
    {% endfor %}
{% endfor %}