微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

类别和标签的新闻 URL 问题

如何解决类别和标签的新闻 URL 问题

以下是我使新闻页面 URL 用户友好的代码。详细信息页面 URL 对此很有效,但不适用于类别和标签

News:
type: Extbase
limitToPages:
  - 16
extension: News
plugin: Pi1
routes:
  -
    routePath: '/page/{page}'
    _controller: 'News::list'
    _arguments:
      page: '@widget_0/currentPage'
  -
    routePath: '/{news_title}'
    _controller: 'News::detail'
    _arguments:
      news_title: news
  -
    routePath: '/topic/{category_name}'
    _controller: 'News::list'
    _arguments:
      category_name: overwriteDemand/categories
  - 
    routePath: '/tag/{tag_name}'
      _controller: 'News::list'
      _arguments:
        tag_name: 'overwriteDemand/tags'
defaultController: 'News::list'
defaults:
  page: '0'
requirements:
  news_title: '^[a-zA-Z0-9].*$'
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: path_segment
  tag_name:
    type: PersistedaliasMapper
    tableName: tx_news_domain_model_tag
    routeFieldName: slug

任何人,请帮我找出这是怎么回事? 我已经评论skipControllerAndAction = 1

Typo3 版本 - 10.4.16, 新闻 - 8.5.2

谢谢!

解决方法

您的类别路由路径不符合您定义的要求(没有 news_title)。

Documentation 说:

如果用于生成 URL 的输入不符合要求,路由增强器不提供变体,并将参数作为常规查询参数添加到 URL。

只需将需求移动到它们所属的 routePath 中即可(详细视图的那个)。

更新:更正了 YAML 以阐明所需的更改

News:
    ...
    routes:
      -
        ...
      -
        routePath: '/{news_title}'
        _controller: 'News::detail'
        _arguments:
          news_title: news
        requirements:
          news_title: '^[a-zA-Z0-9].*$'
    defaultController: 'News::list'
    defaults:
      page: '1'        
    aspects:
      news_title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      ...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。