TYPO3 9.5 LTS routeEnhancers for news with uid 使路径唯一

god*_*ove 1 typo3 typo3-9.x

您好,我在 TYPO3 Slack 频道上发现了以下内容,作为一个人正在使用的内容。这个片段yaml存在于/config/my-websitename/config.yaml...

routeEnhancers:
  NewsList:
    type: Extbase
    limitToPages: [2,20,21,22,92]
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/p{page}'
        _controller: 'News::list'
        _arguments: {'page': '@widget_0/currentPage'}
      - routePath: '/{news_title}'
        _controller: 'News::detail'
        _arguments: {'news_title': 'news'}
    defaultController: 'News::list'
    defaults:
      page: '0'
    requirements:
      page: '\d+'
      news_title: '^[a-zA-Z0-9].*$'
    aspects:
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'
      news_title:
        type: PersistedAliasMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldName: 'path_segment'
Run Code Online (Sandbox Code Playgroud)

问题

但是我注意到当我有多篇具有相同标题的文章时,没有唯一的 URL。

问题

如何将文章添加uid到路径中以使其独一无二,或者这是一个好主意?我发现它在文档中被忽略了,但不知道如何让它工作来扩展我已经拥有的东西,或者是否有更好的例子有人可以给我关于如何获取新闻的唯一网址?

https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html#persistedpatternmapper

小智 5

答案

routeEnhancers:
  NewsPlugin:
    type: Extbase
    extension: 'News'
    plugin: 'Pi1'
    routes:
      - { routePath: '/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
    defaultController: 'News::list'
    aspects:
      news_title:
        type: PersistedPatternMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
        routeFieldResult: '{path_segment}-{uid}'
Run Code Online (Sandbox Code Playgroud)