【问题标题】:How to properly set url-routing for tx-news in TYPO3 9.5.5?如何在 TYPO3 9.5.5 中正确设置 tx-news 的 url-routing?
【发布时间】:2019-04-18 09:48:07
【问题描述】:

我使用 TYPO3 V9.5.5 和 PHP V7.2.10。还安装了 tx-news 插件。站点配置已设置并可以正常工作。但是,如果我为新闻详细信息添加 routeEnhancers,它不会在 url 中显示。它总是看起来像:http://p510984.mittwaldserver.info/aktuell/detail?tx_news_pi1%5Bnews%5D=5&cHash=c68f25c1ef4b5bd7320220373cfed332

我在 stackoverflow 和 google 中搜索了解决方案。我还阅读了新闻扩展的手册https://docs.typo3.org/typo3cms/extensions/news/stable/AdministratorManual/BestPractice/Routing/

即使是 TYPO3 和 PHP 缓存刷新也无济于事。

目前我有以下代码:

routeEnhancers:
  NewsPlugin:
    type: Extbase
    limitToPages:
      - 17
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
    defaultController: 'News::list'
    defaults:
      page: '0'
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment

是否需要“defaultController and defaults: page: 0”?

【问题讨论】:

  • 在方面,您似乎拼错了“新闻标题”。它应该是“news_title”(与路由 -> 参数中的相同)。
  • @Nitori:谢谢你给我看错字。但不幸的是,这并没有改变任何事情。
  • 我可以解决它!在我从 TYPO3 V8.7 获取的 Sitepackage 中,我忘记了我有以下代码:plugin.tx_news.seetings.link.skipControllerAndAction = 1。在我取消注释后,它就像一个魅力。

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


【解决方案1】:

正如Nitori在评论中已经提到的,你需要统一news_title/news-title的拼写。

但这似乎不是您唯一的问题。如果没有方面,您的 URL 至少应该如下所示:

http://p510984.mittwaldserver.info/aktuell/detail/5&cHash=c68f25c1ef4b5bd7320220373cfed332

这意味着,整个路由当前并未应用于您的详细信息页面。

当您使用limitToPages时,请检查17是否是您详情页的UID。


对于分页小部件、类别插件等,您需要将相关页面 UID 添加到limitToPages,当然还需要扩展您的路线。 The news documentation 显示了这些用例的示例。

【讨论】:

  • @sebkin:谢谢你的提示。是的 17 是详细信息页面的 ID。即使没有方面部分,它也会显示如下网址:p510984.mittwaldserver.info/aktuell/… 这种行为很奇怪?!所以我想知道它是否适用于 TYPO3 V9.5.5?
  • 如果您从配置中删除limitToPages(然后清除所有缓存)是否有帮助?我将您的配置复制到我的本地环境中。在我应用所描述的更改后,它按预期工作。
  • @sebkin:我删除了limitToPages,它并没有改变任何东西。你用 TYPO3 V9.5.5 测试过吗?
  • 是的,它是 TYPO3 9.5.5。由于缩进对于 YAML 配置很重要,因此最好在您的问题中更新配置。
  • 链接是如何生成的?使用 n:link viewhelper?还是自定义的东西(f:link.acton 或类似的)?如果是后者,我注意到从 url 参数中省略 controlleraction 可能会导致问题。
【解决方案2】:

这是我的配置,对我来说很好,也许这有帮助......

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: '/{category-name}/page-{page}'
    _controller: 'News::list'
    _arguments:
      category-name: overwriteDemand/categories
      page: '@widget_0/currentPage'
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

【讨论】:

    【解决方案3】:

    对我来说,这个效果很好:

    routeEnhancers:
      # news rewrites
      News:
        type: Extbase
        #limitToPages:
        #  - 67
        extension: News
        plugin: Pi1
        routes:
          - { routePath: '/{news-title}', _controller: 'News::detail', _arguments: { news-title: news } }
          #- { routePath: '/cat/{news-cat}', _controller: 'News::list', _arguments: { news-cat: overwriteDemand/categories } }
        defaultController: 'News::list'
        defaults:
          page: '0'
        aspects:
          news-title:
            type: PersistedAliasMapper
            tableName: tx_news_domain_model_news
            routeFieldName: path_segment
          news-cat:
            type: PersistedAliasMapper
            tableName: sys_category
            routeFieldName: slug
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多