如何在symfony2中的枝条模板中访问存储库功能 [英] How can i access repository functions in twig template in symfony2
本文介绍了如何在symfony2中的枝条模板中访问存储库功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 class categroies
和 class Products
。
在我的存储库中,我有函数
In my repository i have function
getProducts($ categoryid,$ location)
我需要在这样的树枝模板中循环
I need to loop in twig template like this
{% for category in categories %}
--{{ category.name }}--
{% for product in getProducts(category.id,location) %}
--{{ product.name }}--
{% endfor %}
{% endfor %}
或在那里任何更好的方式
or is there any better way for that
推荐答案
你不应该。这是业务逻辑,不应该出现在模板中。一个解决方案是在控制器和模板调用中创建一个新的动作。
You shouldn't. Thats business logic, that should not appear in templates. One solution is to create a new action within a controller and in your template call
{% render '@MyBundle:Product:list' with {category: category.id} %}
这篇关于如何在symfony2中的枝条模板中访问存储库功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文