首页 > 解决方案 > TYPO3 路由:插件中的每条路由都必须是唯一的?

问题描述

似乎每个“routePath”在同一个插件中都必须是唯一的,即使对于不同的操作也是如此,这在我看来是设计错误或错误。

EXT:news 的示例,其中包含带有操作“列表”和“详细信息”的插件“Pi1”,使用默认设置(https://docs.typo3.org/p/georgringer/news/8.6/en-us/AdministratorManual/ BestPractice/Routing/Index.html#basic-setup-include-categories-tags-and-the-rss-atom-feed )。当新闻记录和新闻类别记录(例如“hello-world”)具有相同的 slug 时,您会遇到问题,路由“news/list/hello-world”不会列出类别“hello world”的新闻" 因为“hello world”被识别为新闻标题(只是因为它是在站点配置中的类别之前配置的)。

在这种情况下该怎么办?使用配置选项“limitToPages”(让编辑器添加新插件时不理想)?将其拆分为不同的插件(第三方扩展无法实现)?为 routePath 加前缀,例如“category-*”(当编辑使用这个 slug 创建新闻时,什么也无济于事)?

标签: typo3url-routingtx-newstypo3-10.x

解决方案


不,很抱歉,这不是设计错误,而是配置错误或数据冲突。

无论是人还是机器/程序都无法确定您现在是否意味着具有两个或多个路由的 url 的有效部分,它检查进一步的数据并且两者都有一个有效的值,因此两者都是匹配的并且是“有效的”路线。

但是由于只能执行一条路线,因此您可以实施或说执行第一个或最后一个,已完成(不确定当前是哪一个)。

因此,您的路线配置根本不是确定性的。如果两者都被认为有效且匹配,您可以更改两条路线的顺序以更改哪条路线将获胜。

因此,您有以下选项可以更具确定性:

  1. 不同页面上的单独列表和详细信息,并以此方式区分
  2. 为详细路由路径使用前缀路径
  3. 为类别和/或标签名称 routePaths 的 routePaths 添加前缀

也许将它作为示例或在新闻扩展的文档中发布会更好。但是由于有很多不同的用例和星座,所以只能有例子。必须针对该实例和项目需求正确设置它们。(这确实适用于所有插件,不仅如此ext:news。)

routeEnhancers:
  News:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/'
        _controller: 'News::list'
      - routePath: '/page-{page}'
        _controller: 'News::list'
        _arguments:
          page: '@widget_0/currentPage'
      # detail subroute prefixed
      - routePath: '/detail/{news-title}'
        _controller: 'News::detail'
        _arguments:
          news-title: news
      # list category subroute prefixed
      - routePath: '/category/{category-name}'
        _controller: 'News::list'
        _arguments:
          category-name: overwriteDemand/categories
      # list tag subroute prefixed
      - routePath: '/tag/{tag-name}'
        _controller: 'News::list'
        _arguments:
          tag-name: overwriteDemand/tags
    defaultController: 'News::list'
    defaults:
      page: '0'
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'
      category-name:
        type: PersistedAliasMapper
        tableName: sys_category
        routeFieldName: slug
      tag-name:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_tag
        routeFieldName: slug
  PageTypeSuffix:
    type: PageType
    map:
      'feed.xml': 9818

推荐阅读