我目前正在使用FOSCommentBundle来获取Rest api最佳实践的示例
在此捆绑包中使用具有不同选项的分拣(或排序)服务,使用日期asc和日期desc进行排序,但此服务未在排序提供程序数组中注入(在排序类服务内)
通过“页码”或“日期”范围以oder页面的方式重复使用
parameters:
# The sorting factory class
cms_content.sorting_factory.class: CMS\Bundle\ContentBundle\Sorting\SortingFactory
# Provide to sort by date
cms_content.sorter.date.class: CMS\Bundle\ContentBundle\Sorting\DateSorting
# Provide to sort by page number
cms_content.sorter.page_nb.class: CMS\Bundle\ContentBundle\Sorting\PageNbSorting
#
sorter_sevices_aliases:
- 'cms_content.sorter.page_nb_desc'
- 'cms_content.sorter.page_nb_asc'
- 'cms_content.sorter.date_desc'
- 'cms_content.sorter.date_asc'
services:
# sort by page nb asc
cms_content.sorter.page_nb_asc:
class: '%cms_content.sorter.page_nb.class%'
public: false
tags:
- { name: cms_content.sorter, alias: page_nb_asc }
arguments: [ASC]
# sort by page nb dsc
cms_content.sorter.page_nb_desc:
class: '%cms_content.sorter.page_nb.class%'
public: false
tags:
- { name: cms_content.sorter, alias: page_nb_desc }
arguments: [DESC]
# sort by date asc
cms_content.sorter.date_asc:
class: '%cms_content.sorter.date.class%'
public: false
tags:
- { name: cms_content.sorter, alias: date_asc }
arguments: [ASC]
# sort by date desc
cms_content.sorter.date_desc:
class: '%cms_content.sorter.date.class%'
public: false
tags:
- { name: cms_content.sorter, alias: date_desc }
arguments: [DESC]
# the sorting factory (may be construct with empty array )
cms_content.sorting_factory:
class: '%cms_content.sorting_factory.class%'
arguments: ['%sorter_sevices_aliases%', '%cms_content.sorting_factory.default_sorter%']
我在将排序工厂中声明为私有的服务作为可能的分拣机提供程序数组
时遇到了一些麻烦答案 0 :(得分:0)
糟糕的做法,我犯了一个错误,服务应该直接注入,而不是通过像这样的数组引用:
# the sorting factory (may be contruct with empty array )
cms_content.sorting_factory:
class: '%cms_content.sorting_factory.class%'
arguments: [['@cms_content.sorter.page_nb_asc', '@cms_content.sorter.page_nb_desc', '@cms_content.sorter.date_asc', '@cms_content.sorter.date_desc'], '%cms_content.sorting_factory.default_sorter%']