【问题标题】:Optional routes with routeEnhancers in TYPO3TYPO3 中带有 routeEnhancers 的可选路线
【发布时间】:2021-12-01 09:39:18
【问题描述】:

我正在努力让 TYPO3 插件的以下路线工作:

  1. example.com/page/ -> 不工作!
  2. example.com/page/a-z/a/ -> 工作
  3. example.com/page/a-z/a/more/2/ -> 工作
  4. example.com/page/page-2/ -> 不工作!

URI 如下所示:

example.com/page?tx_myextension_list[controller]=MyController&tx_myextension_list[currentPage]=2&tx_myextension_list[selectedLetter]=&cHash=6258466362eee8ea43be8634002c883f

我的错误:

Symfony\Component\Routing\Exception\InvalidParameterException:路由“tx_myextension_list_1”的参数“uf29714be1a983f4b1a864d48e1b6ae”必须匹配“[a-zA-Z]{1}”(“”给定)以生成相应的 URL。

如果我删除空参数tx_myextension_list[selectedLetter] URL 1 正在工作,但 URL 3 看起来像这个 URL 4 并且行为像这样。

这是我的配置:

routeEnhancers:
  MyPluginList:
    type: Extbase
    extension: MyExtension
    plugin: list
    routes:
      -
        routePath: '/a-z/{letter}'
        _controller: 'MyController::list'
        _arguments:
          letter: 'selectedLetter'
      -
        routePath: '/a-z/{letter}/more/{page}'
        _controller: 'MyController::list'
        _arguments:
          letter: 'selectedLetter'
          page: 'currentPage'
      -
        routePath: 'page-{page}'
        _controller: 'MyController::list'
        _arguments:
          page: 'currentPage'
    defaultController: 'MyController::list'
    requirements:
      letter: '^[a-zA-Z]{1}'
      page: '\d+'
    defaults:
      letter: ''
      page: '0'
    aspects:
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'
      letter:
        type: StaticValueMapper
        map:
          a: A
          b: B
          c: C
          d: D
          e: E
          f: F
          g: G
          h: H
          i: I
          j: J
          k: K
          l: L
          m: M
          n: N
          o: O
          p: P
          q: Q
          r: R
          s: S
          t: T
          u: U
          v: V
          w: W
          x: X
          y: Y
          z: Z

【问题讨论】:

    标签: routes typo3 typo3-10.x


    【解决方案1】:

    我想你只是在以下位置忘记了一个“/”:

    routePath: 'page-{page}'
    _controller: 'MyController::list'
    _arguments:
        page: 'currentPage'
    

    因此生成了“example.com/page/page-2/”wong。

    还可以查看要求的文档:https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Routing/AdvancedRoutingConfiguration.html#aspect-precedence 如果您使用的是地图,则无需为字母添加要求。

    另一个问题应该是您的信件的默认值。因为空字符串不符合您的要求/地图。

    这就是错误告诉你的:

    must match "[a-zA-Z]{1}" ("" given)
    

    【讨论】:

      猜你喜欢
      • 2020-01-26
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2013-05-07
      • 1970-01-01
      相关资源
      最近更新 更多