【问题标题】:TYPO3 routing: every route has to be unique within a plugin?TYPO3 路由:插件中的每条路由都必须是唯一的?
【发布时间】:2021-10-16 14:44:02
【问题描述】:

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

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

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

【问题讨论】:

  • 它甚至必须在所有扩展的所有插件中都是唯一的?这意味着我不能在 EXT:news 中使用 slug/aspect “hello-world”,而在完全不同的扩展名中使用相同的名称!?

标签: typo3 url-routing tx-news typo3-10.x


【解决方案1】:

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

无论是人还是机器/程序都无法确定您现在的意思是 具有两个或多个路由的 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

【讨论】:

  • EXT:realurl 没有这个问题,因为它考虑了整个路径。
  • 我在不同的页面上有列表和详细信息,但这无济于事,即使对于新闻列表,“hello-world”也被识别为新闻标题(也许设置“limitToPages”有帮助)。为路径添加前缀是一个很大的限制,尤其是在需要短 URL 时。
猜你喜欢
  • 2015-03-27
  • 2012-06-14
  • 2016-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-27
  • 1970-01-01
相关资源
最近更新 更多