路徑中的靜態部分在TYPO3 RouteEnhancer中是可選還是必需的?

huangapple go评论51阅读模式
英文:

Are static segments of routePath in TYPO3 RouteEnhancer optional or mandatory?

问题

自 TYPO3 版本 9.5 开始,RouteEnhancers 可用于将扩展的参数翻译为美观易读的 URL 路径。通常包含一个“静态关键字(之前对某些 TYPO3 人员来说被称为“postVarSets”关键字)”,以及基于扩展记录的 path_segment 字段等动态部分,如下所示:

routeEnhancers:
  MyExtDetail:
    type: Plugin
    namespace: tx_myext_pi1
    routePath: '/myext-detail/{uid}'
    aspects:
      uid:
        type: PersistedAliasMapper
        tableName: tx_myext_item
        routeFieldName: path_segment

我的问题是:
在这里,唯一的静态部分像“/myext-detail”绝对是必需的吗(就像我相信 RealUrl 时那样),还是完全可选的,或者这取决于什么?我可以简单地将其省略,还是至少在某些条件下会遇到问题,或者会错过一些优点?

在简单情况下,我尝试将其省略,似乎确实有效,但对于更复杂的情况,我不太确定。

英文:

Since TYPO3 Version 9.5 RouteEnhancers can be used to translate parameters of extensions to nice and human-readable URL-paths. Those usually contain a "static keyword (previously known to some as "postVarSets" keyword for some TYPO3 folks)" and a dynamic part based on f.e. path_segment field of the extension-record, like this:

routeEnhancers:
  MyExtDetail:
    type: Plugin
    namespace: tx_myext_pi1
    routePath: '/myext-detail/{uid}'
    aspects:
      uid:
        type: PersistedAliasMapper
        tableName: tx_myext_item
        routeFieldName: path_segment

My Question is:
Is a unique static part like "/myext-detail" here absolutely mandatory (as I believe it was with RealUrl) or is it entirely optional, or on what does this depend? Can I simply leave it out, or will I run into trouble, at least under certain conditions, or are there advantages I would miss?

I tried leaving it out in a simple case, and it did seem to work, but I'm unsure about more complex scenarios.

答案1

得分: 0

你可能会遇到问题。

但如果你有干净的配置,这并不是必要的。

假设你有两个不同的插件,它们在列表中显示记录并进行分页显示,以及单个记录的详细信息:
如果这些插件位于不同的页面上,你可以仅通过记录号配置单个/详细显示(取决于你从另一个表中选择记录的页面)。
甚至分页的页面也可以配置而不需要额外的路径段:只需在页面号之前添加一个前缀,如 page-
尽管分页基于不同的URL参数(如 tx_plugin1[page]tx_plugin2[page] ),但生成的URL可能与配置是页面相关的看起来一样。

示例:


  Record1Plugin:
    type: Extbase
    limitToPages:
      - 123
    extension: MyExt
    plugin: Record1Plugin
    routes:
      -
        routePath: '/page-{page}'
        _controller: 'Record1::list'
        _arguments:
          page: showPage
      -
        routePath: '/{record1Id}'
        _controller: 'Record1::show'
        _arguments:
          record1id: record1
    defaultController: 'Record1::list'
    defaults:
      page: '0'
    requirements:
      page: \d+

  Record2Plugin:
    type: Extbase
    limitToPages:
      - 456
    extension: MyExt
    plugin: Record2Plugin
    routes:
      -
        routePath: '/page-{page}'
        _controller: 'Record1::list'
        _arguments:
          page: showPage
      -
        routePath: '/{record2Id}'
        _controller: 'Record2::show'
        _arguments:
          record2Id: record2
    defaultController: 'Record2::list'
    defaults:
      page: '0'
    requirements:
      page: \d+
英文:

You may come in trouble.

But it is not necessary if you have a clean configuration.

Assuming you have two different plugins which show records in a list with pagination and as single (detail):
if these plugins reside on different pages you could configure single/detail display with just the record number (depending on the page you select the record from another table.)
even the page of the pagination could be configured without additional path segment: just add a prefix like page- to the page number.
and although the paginations are based on different URL parameters (like tx_plugin1[page] and tx_plugin2[page]) the resulting URL may look the same as the configuration would be page dependent.

example:


  Record1Plugin:
    type: Extbase
    limitToPages:
      - 123
    extension: MyExt
    plugin: Record1Plugin
    routes:
      -
        routePath: '/page-{page}'
        _controller: 'Record1::list'
        _arguments:
          page: showPage
      -
        routePath: '/{record1Id}'
        _controller: 'Record1::show'
        _arguments:
          record1id: record1
    defaultController: 'Record1::list'
    defaults:
      page: '0'
    requirements:
      page: \d+

  Record2Plugin:
    type: Extbase
    limitToPages:
      - 456
    extension: MyExt
    plugin: Record2Plugin
    routes:
      -
        routePath: '/page-{page}'
        _controller: 'Record1::list'
        _arguments:
          page: showPage
      -
        routePath: '/{record2Id}'
        _controller: 'Record2::show'
        _arguments:
          record2Id: record2
    defaultController: 'Record2::list'
    defaults:
      page: '0'
    requirements:
      page: \d+

huangapple
  • 本文由 发表于 2023年5月17日 21:00:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76272396.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定