【问题标题】:TYPO3 v10.4.9 News Listview URL-ConfigurationTYPO3 v10.4.9 新闻列表视图 URL-配置
【发布时间】:2021-02-19 07:38:49
【问题描述】:

我目前正在开展一个在各个页面上使用新闻扩展的项目。为了摆脱神秘的 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。

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

【问题讨论】:

  • 问题是您的增强器适用于每个 tx_news_pi1 插件,并假定它是 News::detail。您应该为列表页面添加路由,或者(更简单)只需添加 limitToPages: [<IDs of detail pages>]
  • 感谢您的回答!我已经尝试过了,但不幸的是在访问相应的列表页面时发生了同样的错误。 (列表页的 ID 为 46,详细信息页的 ID 为 142)。但是当我输入 limitToPages: [142] 时我无法访问 46
  • 你试过limitToPages: [46,142]了吗?
  • 不幸的是也不起作用

标签: url yaml frontend typo3 rewriting


【解决方案1】:

(1/1) Symfony\Component\Routing\Exception\InvalidParameterException 路由“tx_news_pi1_0”的参数“tx_news_pi1__news”必须匹配 “.+”(“”给定)生成对应的URL。

异常说生成URL的参数为空""。您已将 YAML 文件配置为从 path_segment 字段中获取值以生成 url。

新闻标题: 类型:PersistedAliasMapper 表名:tx_news_domain_model_news routeFieldName: path_segment

意味着一些记录有一个空的path_segment/slug。这就是为什么仅在某些页面中不断发生异常的原因。检查所有新闻记录是否在 path_segment 字段中具有值。

【讨论】:

  • 救命稻草!事实上,我有几个空的 path_segments,在我再次生成它们之后,错误消息消失了。有一个后备队会很好。例如新闻的uid。这可能吗?
【解决方案2】:

此配置意味着您网站的每个页面都必须有新闻标题。您需要使用 limitToPages 限制为详细信息页面 pid:

routeEnhancers:
  News:
    limitToPages: [10]

【讨论】:

  • 感谢您的回答!我已经尝试过了,但不幸的是,在访问相应的列表页面时发生了同样的错误。 (列表页的 ID 为 46,详细信息页的 ID 为 142)。但是当我输入limitToPages: [142] 时我无法访问 46
【解决方案3】:

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

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

【讨论】:

  • 感谢您的回答!但它只是行不通..:(我尝试了几十种组合和可能性,但一旦我设法让列表页面工作,详细视图就有一个神秘的 URL。控制器似乎有问题,因为如果我将defaultController 设置为'News::detail',我会得到说话的URL,如果我将它设置为'News::List',我可以访问列表视图,但是对于详细页面有神秘的URL,尽管'routePath: '/{news_title}' 的控制器已设置到'News::detail'
  • 你必须配置两个控制器。看看文档。也许您必须将 TYPO3 和 EXT:news 更新到最新版本。我扩展我的答案。
【解决方案4】:

遇到同样的问题。

问题出在接缝处

link {
    skipControllerAndAction = 1
}

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 2018-11-13
    • 2018-11-30
    相关资源
    最近更新 更多