【问题标题】:Problem with News URL of Category and tags类别和标签的新闻 URL 问题
【发布时间】:2021-09-02 20:10:55
【问题描述】:

以下是使新闻页面 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

谢谢!

【问题讨论】:

    标签: typo3 seo tx-news typo3-10.x


    【解决方案1】:

    您的类别 routePath 不符合您定义的要求(没有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
          ...
    

    【讨论】:

    • 嗨,谢谢您的回复。 news_title 用于详细信息页面。我已经为类别提供了 /topic/{category_name}
    • 您对news_title 的要求是全局定义的,因此它是您所有 新闻路线的要求。所以你的routePath: '/topic/{category_name}'也必须有一个news_title——事实并非如此。您的要求应移至 routePath: '/{news_title}' 的块中,因此仅这些路线需要它。
    • 谢谢。我只需要相应地列出新闻标签和类别。所以我不需要那里的新闻标题。谢谢你的解释,我会检查它。
    猜你喜欢
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    相关资源
    最近更新 更多