【问题标题】:How to get rid of the cHash with routing enhancers?如何使用路由增强器摆脱 cHash?
【发布时间】:2019-02-13 15:28:49
【问题描述】:

在使用带有自定义扩展的路由增强器时,我想去掉 cHash get 参数。

TYPO3 文档/变更日志假设这是可能的:

如果你真的要求永远不要有 cHash 参数, 确保所有占位符对什么都有严格的定义 可能是页面段的结果...

严格定义究竟是什么意思。

这是我的路由配置:

routeEnhancers:
  ExecutiveSearchResultList:
    type: Extbase
    extension: executivesearch
    plugin: searchresultlist
    routes:
        - { routePath: '/list/{page}', _controller: 'Search::searchResultList', _arguments: {'page': 'page'} }
    defaultController: 'Search::searchResultList'
    defaults:
      page: '1'
      action: 'searchResultList'
      controller: 'Search'
    requirements:
      page: '\d+'

结果是

/path/to/my-page/list/1?cHash=6cd242916809d29b799debe824b37fcd

我还有一个 tx_news 的路由,可以正常工作,不要附加 cHash:

NewsPlugin:
    type: Extbase
    extension: news
    plugin: Pi1
    routes:
      - { routePath: '/list/{page}', _controller: 'News::list', _arguments: {'page': '@widget_0/currentPage'} }
      - { routePath: '/tag/{tag_name}', _controller: 'News::list', _arguments: {'tag_name': 'overwriteDemand/tags'}}
      - { routePath: '/news/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
      - { routePath: '/archive/{year}/{month}', _controller: 'News::archive' }
    defaultController: 'News::list'
    aspects:
      news_title:
        type: PersistedAliasMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldName: 'path_segment'
    defaults:
      page: '0'
    requirements:
      page: '\d+'

【问题讨论】:

标签: routing typo3 typo3-9.x


【解决方案1】:

我的解决方法是使用 StaticRangeMapper。

提示:目前 TYPO3 内核中的最大值为 1000。

  NewsPlugin:
    type: Extbase
    limitToPages:
      - 56
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/list/{page}'
        _controller: 'News::list'
        _arguments:
          page: '@widget_0/currentPage'
      - routePath: '/detail/{news_title}'
        _controller: 'News::detail'
        _arguments:
          news_title: news
    defaultController: 'News::list'
    defaults:
      page: '0'
    requirements:
      page: \d+
    aspects:
      page:
        type: StaticRangeMapper
        start: '1'
        end: '1000'
      news_title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment

【讨论】:

  • 谢谢,这行得通。但是,正如您所写,这是一种解决方法而不是解决方案。
  • 仅当您的数值范围为 1...1000 时才适用。但也许魔法就是在配置中添加一个映射器。但在某些情况下我不能使用标准映射器之一,也许我必须编写一个自定义映射器,只是为了摆脱 cHash 参数。
  • 当然,你是对的。如果您需要自定义方面的示例,请查看此处:gist.github.com/wazum/e5862338fbc4466bac8c66bf11efdf9e
  • 当所有占位符都有一个aspect配置时,chash就消失了。我添加了一个什么都不做的自定义映射器,只是为了在我实际上不需要的情况下。
猜你喜欢
  • 1970-01-01
  • 2011-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多