如何显示来自树枝对象的所有方法?
How display all methods from an object from twig?
我试图通过 twig dump 获取所有方法的列表。
<div>
{% if listPosts is defined %}
{{ dump(listPosts) }}
{% endif %}
</div>
但我只得到这个列表:
SlidingPagination {#575 ▼
-route: "bissap_forum_topic"
-params: array:2 [▶]
-pageRange: 2
-template: "KnpPaginatorBundle:Pagination:sliding_bissap.html.twig"
-sortableTemplate: "KnpPaginatorBundle:Pagination:sortable_link.html.twig"
-filtrationTemplate: "KnpPaginatorBundle:Pagination:filtration.html.twig"
#currentPageNumber: "1"
#numItemsPerPage: 8
#items: array:8 [▶]
#totalCount: 11
#paginatorOptions: array:6 [▶]
#customParameters: []
}
如何在 twig 中显示一个对象的所有方法名称?
你需要的是 twig filter。这样你就可以实现一个例如list_functions
在 php 中过滤并从树枝中使用它,例如:
{{ listPosts | list_functions }}
您需要在 php 中实现逻辑,因为您不能直接在 twig 中使用 php。使用 get_class_methode 应该很容易。通过这种方式您可以获得所有函数的列表,但是您必须决定要调用哪个函数。
我试图通过 twig dump 获取所有方法的列表。
<div>
{% if listPosts is defined %}
{{ dump(listPosts) }}
{% endif %}
</div>
但我只得到这个列表:
SlidingPagination {#575 ▼
-route: "bissap_forum_topic"
-params: array:2 [▶]
-pageRange: 2
-template: "KnpPaginatorBundle:Pagination:sliding_bissap.html.twig"
-sortableTemplate: "KnpPaginatorBundle:Pagination:sortable_link.html.twig"
-filtrationTemplate: "KnpPaginatorBundle:Pagination:filtration.html.twig"
#currentPageNumber: "1"
#numItemsPerPage: 8
#items: array:8 [▶]
#totalCount: 11
#paginatorOptions: array:6 [▶]
#customParameters: []
}
如何在 twig 中显示一个对象的所有方法名称?
你需要的是 twig filter。这样你就可以实现一个例如list_functions
在 php 中过滤并从树枝中使用它,例如:
{{ listPosts | list_functions }}
您需要在 php 中实现逻辑,因为您不能直接在 twig 中使用 php。使用 get_class_methode 应该很容易。通过这种方式您可以获得所有函数的列表,但是您必须决定要调用哪个函数。