TYPO3 v10.4.9 News Listview URL-Configuration

问题描述

我目前正在开展一个项目,该项目在各个页面上使用新闻扩展。为了摆脱神秘的 URL,我在 config.yaml添加了以下代码

routeEnhancers:
  News:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/{news_title}'
        _controller: 'News::detail'
        _arguments:
          news_title: news
    defaultController: 'News::detail'
    aspects:
      news_title:
        type: PersistedaliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment

这给了我我想要的某些页面的结果,但对于其他页面,它会引发 FE 错误

(1/1) Symfony\Component\Routing\Exception\InvalidParameterException
Parameter "tx_news_pi1__news" for route "tx_news_pi1_0" must match ".+" ("" given) to generate a corresponding URL.

错误出现在某些页面上,其中包括新闻插件并应显示列表视图。奇怪的是,由于这是一个常规页面,它应该有一个常规 URL,无需上述代码即可完美运行。更奇怪的是,当手动输入所需的朗读 URL 时,我可以到达新闻详细信息页面。因此,新闻详细信息视图的 URL 重写适用于每个页面,但它会破坏之前有效的其他列表视图页面的 URL。

我花了几个小时试图找出错误的来源并发现:

  • 如果我将 settings.categoryConjunctionOR 更改为 AND,列表视图可以工作,但逻辑上会显示错误的结果
  • 当我更改 settings.categories 时会发生同样的事情,即当我添加一个完整的类别而不是一个子类别时

Click me to see backend configuration

结论:

  • myproject.local/somepagewithnews 作品
  • myproject.local/somepagewithnews/detail/articleWithSpeakingUrl 作品
  • myproject.local/anotherpagewithnews 不起作用
  • myproject.local/anotherpagewithnews/articleWithSpeakingUrl 有效。请注意,中间没有 /detail/添加它会导致 Page does not exist-Error。

如果没有代码,每个页面和每篇新闻文章都可以正常工作,区别在于文章(不是具有列表视图的页面)具有神秘的 URL。

我希望我的问题是可以理解的,这里有人可以帮助我,因为这让我发疯。 提前致谢!!

解决方法

此配置意味着您网站的每个页面都必须有新闻标题。您需要使用 limitToPages:

限制为详细信息页面 pid
routeEnhancers:
  News:
    limitToPages: [10]
,

您可以为列表视图添加路由:

routes:
      - routePath: '/'
        _controller: 'News::list'

在 EXT:news 的文档中,您可以找到有关路由配置的所有信息:https://docs.typo3.org/p/georgringer/news/8.5/en-us/AdministratorManual/BestPractice/Routing/Index.html?highlight=routeenhanc

来自文档的完整配置:

routeEnhancers:
  News:
    type: Extbase
    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
,

遇到了同样的问题。

看来问题是

link {
    skipControllerAndAction = 1
}

tx_news 配置中。只需将其删除。

在此处找到此解决方案:TYPO3 News routing not working properly...