无限滚动,分页和路线

时间:2019-12-09 08:52:13

标签: php routing typo3 typo3-9.x tx-news

我在TYPO3 9.5.11上使用新闻扩展和无限滚动插件时遇到问题。

我要寻找的是设置2个无限滚动:一个滚动列出每个新闻,另一个滚动滚动按类别列出新闻(使用按类别列出)。它可以正常工作,但是当我按类别列出新闻时,无法像其他滚动条中那样获得可读的URL(例如,我得到*categorie/page-2?tx_news_pi1[action]=list&tx_news_pi1[controller]=News&tx_news_pi1[overwriteDemand][categories]=3&cHash=6ff5f6ee014fec754b5453d9c4afdcc1*而不是categorie/nameofthecategory/page-X)。我希望它足够清楚。

这是我的config.yaml:

routeEnhancers:
  News:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      -
        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
      category-name:
        type: PersistedAliasMapper
        tableName: sys_category
        routeFieldName: slug
      tag-name:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_tag
        routeFieldName: slug
  NewsList:
    type: Plugin
    routePath: '/page-{@widget_0/currentPage}'
    namespace: 'tx_news_pi1'
    aspects:
      '@widget_0/currentPage':
        type: StaticRangeMapper
        start: '1'
        end: '1000' 

有人知道如何设置吗?

谢谢! :-)

编辑:好的,所以我发现使用config.yaml还可以:

routeEnhancers:
  News:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      -
        routePath: '/{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: '/{category-name}/{page}'
        _controller: 'News::list'
        _arguments:
          category-name: overwriteDemand/categories
          page: '@widget_0/currentPage'
    defaultController: 'News::list'
    defaults:
      page: '1'
    requirements:
      page: '\d+'
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      category-name:
        type: PersistedAliasMapper
        tableName: sys_category
        routeFieldName: slug
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'

此设置的问题是我遇到了此处解释的错误:Bug #86895 - routeEnhancer not working correct for paginate widget。这意味着在我的主页上,如果我输入URL */2并加载第一页,则会得到错误的URL。无论出于何种原因,我都不会在类别过滤页面中遇到它……

我尝试申请the patch mentionned in Forge,不幸的是没有成功。

1 个答案:

答案 0 :(得分:0)

好的,所以我终于找到了解决方案。我完全忘记了您可以指定在其上运行指定路线的页面。这是最终版本:

routeEnhancers:
  News:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      -
        routePath: '/{news-title}'
        _controller: 'News::detail'
        _arguments:
          news-title: news
      - routePath: '/{category-name}'
        _controller: 'News::list'
        _arguments:
          category-name: overwriteDemand/categories
      -
        routePath: '/{category-name}/{page}'
        _controller: 'News::list'
        _arguments:
          category-name: overwriteDemand/categories
          page: '@widget_0/currentPage'
    defaultController: 'News::list'
    defaults:
      page: '1'
    requirements:
      page: '\d+'
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      category-name:
        type: PersistedAliasMapper
        tableName: sys_category
        routeFieldName: slug
      page:
        type: StaticRangeMapper
        start: '1'
        end: '1000'
  NewsList:
    type: Plugin
    limitToPages: [3] #(3 is my main's page pid)
    routePath: '/{@widget_0/currentPage}'
    namespace: 'tx_news_pi1'
    aspects:
      '@widget_0/currentPage':
        type: StaticRangeMapper
        start: '1'
        end: '1000'

通过这种方式,基于插件的路由器可以在主页上运行(即使我从第2页到第1页),也可以将基于EXTBase的路由用于该类别。