人类可读的新闻细节 URL

Human readable news detail URL

我希望我的新闻详细信息页面的 URL 如下所示:

示例。com/news/2019/07/22/article-name

如何使用 RouteEnhancers 实现此目的?

到目前为止的代码:

routeEnhancers:
  Detail:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      # Pagination:
      - routePath: '/page-{page}'
        _controller: 'News::list'
        _arguments:
          page: '@widget_0/currentPage'
        requirements:
          page: '\d+'
      - routePath: '/{date-year}/{date-month}/{date-day}/{news-title}'
        _controller: 'News::detail'
        _arguments:
          date-month: 'overwriteDemand/month'
          date-year: 'overwriteDemand/year'
          date-day: 'overwriteDemand/day'
          news-title: news
        requirements:
          news-title: '\w+'
          date-month: '\d+'
          date-year: '\d+'
          date-day: '\d+'
      # Date year:
      - routePath: '/{date-year}'
        _controller: 'News::list'
        _arguments:
          date-month: 'overwriteDemand/month'
          date-year: 'overwriteDemand/year'
          page: '@widget_0/currentPage'
        requirements:
          date-year: '\d+'
      # Date year + pagination:
      - routePath: '/{date-year}/page-{page}'
        _controller: 'News::list'
        _arguments:
          date-year: 'overwriteDemand/year'
          page: '@widget_0/currentPage'
        requirements:
          date-year: '\d+'
          page: '\d+'
      # Date year/month:
      - routePath: '/{date-year}/{date-month}'
        _controller: 'News::list'
        _arguments:
          date-month: 'overwriteDemand/month'
          date-year: 'overwriteDemand/year'
          page: '@widget_0/currentPage'
        requirements:
          date-month: '\d+'
          date-year: '\d+'
      # Date year/month + pagination:
      - routePath: '/{date-year}/{date-month}/page-{page}'
        _controller: 'News::list'
        _arguments:
          date-month: 'overwriteDemand/month'
          date-year: 'overwriteDemand/year'
          page: '@widget_0/currentPage'
        requirements:
          date-month: '\d+'
          date-year: '\d+'
          page: '\d+'
    defaultController: 'News::list'
    defaults:
      page: '0'
      date-month: ''
      date-year: ''
      date-day: ''
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      page:
        type: StaticRangeMapper
        start: '1'
        end: '25'
      date-month:
        type: StaticValueMapper
        map:
          january: '01'
          february: '02'
          march: '03'
          april: '04'
          may: '05'
          june: '06'
          july: '07'
          august: '08'
          september: '09'
          october: '10'
          november: '11'
          december: '12'
      date-year:
        type: StaticRangeMapper
        start: '2000'
        end: '2030'

当前输出:

例子。com/news/tx_news_pi1%5Baction%5D=细节&tx_news_pi1%5Bcontroller%5D=新闻&tx_news_pi1%5Bnews%5D=2&cHash=b38beb0089692fa008e37545c57d48dc

不需要特殊的巫术,这是一个有效的配置:

routeEnhancers:
  DateMenu:
    limitToPages: [5,4,3]
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      # Pagination:
      - routePath: '/page-{page}'
        _controller: 'News::list'
        _arguments:
          page: '@widget_0/currentPage'
        requirements:
          page: '\d+'
      - routePath: '/{date-year}/{date-month}/{date-day}/{news-title}'
        _controller: 'News::detail'
        _arguments:
          news-title: 'news'
          date-month: 'month'
          date-year: 'year'
          date-day: 'day'
      # Date year:
      - routePath: '/{date-year}'
        _controller: 'News::list'
        _arguments:
          date-month: 'overwriteDemand/month'
          date-year: 'overwriteDemand/year'
          page: '@widget_0/currentPage'
        requirements:
          date-year: '\d+'
      # Date year + pagination:
      - routePath: '/{date-year}/page-{page}'
        _controller: 'News::list'
        _arguments:
          date-year: 'overwriteDemand/year'
          page: '@widget_0/currentPage'
        requirements:
          date-year: '\d+'
          page: '\d+'
      # Date year/month:
      - routePath: '/{date-year}/{date-month}'
        _controller: 'News::list'
        _arguments:
          date-month: 'overwriteDemand/month'
          date-year: 'overwriteDemand/year'
          page: '@widget_0/currentPage'
        requirements:
          date-month: '\d+'
          date-year: '\d+'
      # Date year/month + pagination:
      - routePath: '/{date-year}/{date-month}/page-{page}'
        _controller: 'News::list'
        _arguments:
          date-month: 'overwriteDemand/month'
          date-year: 'overwriteDemand/year'
          page: '@widget_0/currentPage'
        requirements:
          date-month: '\d+'
          date-year: '\d+'
          page: '\d+'
    defaultController: 'News::list'
    defaults:
      page: '0'
      date-month: ''
      date-year: ''
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      page:
        type: StaticRangeMapper
        start: '1'
        end: '25'
      date-month:
        type: StaticValueMapper
        map:
          januar: '1'
          februar: '2'
          maerz: '3'
          april: '4'
          mai: '5'
          juni: '6'
          juli: '7'
          august: '8'
          september: '9'
          oktober: '10'
          november: '11'
          dezember: '12'
      date-year:
        type: StaticRangeMapper
        start: '2019'
        end: '2030'
      date-day:
        type: StaticRangeMapper
        start: '01'
        end: '31'

plugin.tx_news.settings.link.hrDate = 1必须设置好,否则你不会得到\GeorgRinger\News\ViewHelpers\LinkViewHelper

生成的月、日、年参数