doujiang6944 2011-11-28 10:00
浏览 38

在Symfony 2中使用TWIG的嵌套列表

i have in database

Category:
id | name
1  | first
2  | second
etc

and:

News:
id | category | name
1  | 1        | one
2  | 2        | two
3  | 1        | three
4  | 2        | four
5  | 2        | five

ETC.

how is the best method for show this in TWIG?

FIRST
- one
- three
SECOND
- two
- four
- five

etc.

in Symfony 1.4 i can use get data from template PHP, but in Symfony 2 i must get all data in controllor, but how?

  • 写回答

2条回答 默认 最新

  • dongmei1988 2011-11-28 10:25
    关注

    I'm not using Sf2 (yet) so I can't give you exactly what you need, but it should be similar to this:

    • in your controller, get all categories, inner joining with the relation to news (to make sure a single query is used to get all the data needed)
    • in your template, do a for on the categories
    • in that loop, do a for on the current category's relation to news
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改