【问题标题】:Human readable news detail URL人类可读的新闻详细信息 URL
【发布时间】:2019-07-29 10:12:54
【问题描述】:

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

example.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'

当前输出:

example.com/news/tx_news_pi1%5Baction%5D=detail&tx_news_pi1%5Bcontroller%5D=News&tx_news_pi1%5Bnews%5D=2&cHash=b38beb0089692fa008e37545c57d48dc

【问题讨论】:

    标签: typo3 tx-news


    【解决方案1】:

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

    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生成的月、日、年参数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多