【问题标题】:TYPO3 News Routing working but still Hash and other URL parts visibleTYPO3 新闻路由工作但仍然可见哈希和其他 URL 部分
【发布时间】:2020-07-23 12:41:06
【问题描述】:

我在 TYPO3 9.5 中遇到路由和 tx_news 问题。官方的例子我都试过了,问题依旧,不知道是什么原因。

我喜欢有这样的 URL:

...home/news/detail/project-lounge-movetia-2

但我明白了:

...home/news/detail/project-lounge-movetia-2?tx_news_pi1[day]=11&tx_news_pi1[month]=12&tx_news_pi1[year]=2019&cHash=8fd7057d32ae3e3810b76f0bf4a06e39

配置是标准的:

routeEnhancers:
  News:
    type: Extbase
    limitToPages:
      - 40
      - 54
      - 55
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/'
        _controller: 'News::list'
      - routePath: '/page-{page}'
        _controller: 'News::list'
        _arguments:
          page: '@widget_0/currentPage'
      - routePath: '/{news-title}'
        _controller: 'News::detail'
        _arguments:
          news-title: news
      - routePath: '/{category-name}'
        _controller: 'News::list'
        _arguments:
          category-name: overwriteDemand/categories
      - routePath: '/{tag-name}'
        _controller: 'News::list'
        _arguments:
          tag-name: overwriteDemand/tags
    defaultController: 'News::list'
    defaults:
      page: '40'
    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
    requirements:
      page: '\d+'

新闻标题得到正确“增强”,但其余部分仍然存在(哈希、id 等)我不知道为什么会发生这种情况。我读了很多次关于路由的手册,但我不明白。 :(

【问题讨论】:

    标签: url routes typo3-9.x tx-news


    【解决方案1】:

    它应该包含更多内容,如他们的文档中所示

    routeEnhancers:
      News:
        type: Extbase
        limitToPages:
          - 104
        extension: News
        plugin: Pi1
        routes:
          - routePath: '/'
            _controller: 'News::list'
          - routePath: '/page-{page}'
            _controller: 'News::list'
            _arguments:
              page: '@widget_0/currentPage'
          - routePath: '/{news-title}'
            _controller: 'News::detail'
            _arguments:
              news-title: news
          - routePath: '/{category-name}'
            _controller: 'News::list'
            _arguments:
              category-name: overwriteDemand/categories
          - routePath: '/{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
    

    不需要的参数

    实际上像&tx_news_pi1[day]=20&tx_news_pi1[month]=7 这样的日期参数是NOT默认参数,这意味着您复制了一些包含它的 TS sn-p,或者可能是您的一些同事把它放在那里。

    根据News' Humane readable dates documentation 在您的 TypoScript 中搜索 plugin.tx_news.settings.link.hrDate 节点并修改或删除它以摆脱单视图链接中的 date 参数。

    最后,如果您想保留它们,但要使用人类可读的 URL,请查看 newest documentation of the ext:news,它有一个示例,用于通过方面进行正确的日期路由。

    【讨论】:

    • 您好 biesior,感谢您的评论。我有更多代码,我只是展示了重要的东西。但我现在编辑我的帖子以包含所有路由增强器。
    • 您是否尝试添加date-monthdate-year 提到的in the documentation 方面?
    • 谢谢比西奥!问题是,完全相同的 yaml 配置在另一个站点中工作。我可以从字面上复制和粘贴它,它按预期工作。所以除了yaml配置之外肯定有什么问题,但是什么..?扩展生成器会干扰吗?
    • 其他实例是否也在新闻中使用 [day]、[month]、[year] 参数?
    【解决方案2】:

    我找到了解决方案。问题不在于路由,而是原始新闻 URL 包含所有附加参数 {day}{month}{year}。以下 SETUP 设置将其关闭:

    plugin.tx_news.settings.link.hrDate = 0

    禁用它后,生成的原始 URl 如下所示: ?tx_news_pi1[action]=detail&tx_news_pi1[controller]=News&tx_news_pi1[news]=486&cHash=

    现在完美运行。 感谢 biesior 推动我找到解决方案!

    【讨论】:

      猜你喜欢
      • 2018-06-15
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      • 2021-04-22
      • 2012-12-07
      • 2020-05-21
      • 1970-01-01
      相关资源
      最近更新 更多