【问题标题】:routeEnhancer for type plugin with different number of parameter具有不同数量参数的类型插件的 routeEnhancer
【发布时间】:2019-10-14 20:31:46
【问题描述】:

我需要在我的网址中省略一个或多个参数。例如:

domain.tld/page/my-article/
domain.tld/page/cat/2/my-article

两个网址都显示相同的页面。

这适用于第一个变体:

myplugin:
  limitToPages:
    - 80
  type: Plugin
  routePath: '/{uid}'
  namespace: tx_myext_pi1
  requirements:
    uid: '[0-9]{1,4}'
  aspects:
    uid:
      type: PersistedAliasMapper
      tableName: tx_myext_items
      routeFieldName: slug

这是第二个:

myplugin:
  limitToPages:
    - 80
  type: Plugin
  routePath: '/cat/{cat}/{uid}'
  namespace: tx_myext_pi1
  requirements:
    cat '[0-9]{1}'
    uid: '[0-9]{1,4}'
  aspects:
    uid:
      type: PersistedAliasMapper
      tableName: tx_myext_items
      routeFieldName: slug
   cat:
     type: StaticRangeMapper
     start: '1'
     end: '10'

但是我不能让它们都工作......是否有可能定义一个允许忽略 cat 参数的路由增强器?

谢谢!

【问题讨论】:

  • 这不叫“两个网址重复内容”吗?无论如何,如果您有方面的可选变体(如 cat),则必须定义所有可能的变体。在您的情况下,两个 routeEnhancers 'myplugin-uid' & 'myplugin-uid-cat'... 但是如果没有设置参数,您会感到很困惑。更好地改变您的概念,使用独特、简短和清晰的网址。

标签: routing typo3 typo3-9.x


【解决方案1】:

经过几个小时的尝试,我找到了(明显的)解决方案。事实上,如果你介意我不知道的正确定义顺序,那么有很多可能性。

每个 routePath 都属于具有不同名称的不同路由增强器。路径路径必须与行首区别开来:

这行得通:

myplugin1:
routePath: '/{id}'
myplugin2:
'/u/{unit}/{id}'

这个不要:

myplugin1:
routePath: '/{id}'
myplugin2:
'/{id}/u/{unit}'

因为第一项 /{id} 在两个定义中是相同的。

(请记住,由于重复的内容,这通常是一个非常糟糕的主意!有时这并不重要......)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-23
    • 2017-08-04
    • 2011-04-03
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多