简体   繁体   English

TYPO3 9.5 LTS routeEnhancers for news with uid to make path unique

[英]TYPO3 9.5 LTS routeEnhancers for news with uid to make path unique

Hello I found the following on a TYPO3 Slack channel as what one person was using.您好,我在一个 TYPO3 Slack 频道上发现了一个人正在使用的内容。 This snip of yaml exists at the /config/my-websitename/config.yaml ...这个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'

The problem问题

But I noticed that when I have multiple articles with the same title there's not a unique URL.但我注意到,当我有多篇文章标题相同时,没有唯一的 URL。

The question问题

How can I add the article uid to the path to make it unique or is that a good idea?如何将文章uid添加到路径以使其独一无二或者这是一个好主意? I found that it was eluded to in the docs but don't know how to get it working to extend what I have already or if there's a better example someone can give me of how to get unique urls for news?我发现文档中没有提到它,但不知道如何让它工作以扩展我已有的内容,或者是否有更好的示例可以告诉我如何获取新闻的唯一 url?

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

The answer答案

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}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM