【问题标题】:TYPO3 10 Routing - Parameters are emptyTYPO3 10 路由 - 参数为空
【发布时间】:2022-01-17 03:14:08
【问题描述】:

TYPO3 9 Routing - the parameter gets overwritten by the defaults - 1 年零 8 个月后,我们正在尝试更新到 TYPO3 10,然后再更新到 TYPO3 11。如您所见,站点配置非常适合 Typo3 9,但现在不再适用.

routeEnhancers:
  Werbemittelshop:
    type: Extbase
    extension: Mwwerbemittelshop
    plugin: Mwwerbemittelshop
    routes:
      -
        routePath: '/{categoryname}/{categoryname2}/{categoryname3}'
        _controller: 'MwWsCategories::category'
        _arguments:
          categoryname: mwWsCategory
          categoryname2: mwWsCategory2
          categoryname3: mwWsCategory3
      -
        routePath: '/{productname}'
        _controller: 'MwWsCategories::product'
        _arguments:
          productname: mwWsProduct
    defaults:
      categoryname2: ''
      categoryname3: ''
    defaultController: 'MwWsCategories::category'
    aspects:
      categoryname:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug
      categoryname2:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug
      categoryname3:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug
      productname:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwsproducts
        routeFieldName: slug

“产品名称”完全按预期工作。它是一个可读的 url,例如 example.de/test123,它使用控制器的正确操作。

“categoryname2”和“categoryname3”是问题所在。如果我打开 example.de/category1/ 它可以工作,但如果我添加第二个或第三个参数,我的参数是空的(example.de/category1/category2),我不明白。

/**
     * action category
     *
     * @param \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory
     * @param \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory2
     * @param \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory3
     * @return void
     */
    public function categoryAction(
        \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory = null, 
        \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory2 = null, 
        \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory3 = null
    )
    {
        var_dump($this->request->getArguments());
        var_dump($mwWsCategory);
        exit;

你们中有人能找出我的错误吗?我尝试了很多版本,但没有任何效果。如果您有任何疑问或想要更多代码,请直接询问。

提前致谢。

【问题讨论】:

  • 如果您只设置了categoryname,则URL 以'/category' 结尾。这就是您为“MwWsCategories::product”路径定义 URL 的方式。但是给定的类别名称与productname 方面不匹配,因此您最终会处于默认情况:defaultController: 'MwWsCategories::category'- 没有任何参数。
  • 谢谢,但有趣的是:单独的 categoryname 和单独的 productname 工作正常。我不知道为什么,我也有同样的想法,但它确实有效。仅当我将 categoryname 与 categoryname2 组合时,例如:example.com/category1/subcategory1 该组合不起作用...
  • 试一试:您是否尝试过更改订单?所以首先尝试的是产品名称,然后是类别......
  • 不错的主意,我试过了,但并没有改变结果。 example.com/product works example.com/category works example.com/category/subcategory 不起作用但我尝试了一些新的东西。我删除了默认值“categoryname2”,现在 example.com/category/subcategory 有效,但显然 example.com/category 不再有效。这有什么帮助吗?
  • 我现在设法收到一条错误消息:“页面未找到该页面不存在或无法访问。原因:请求的页面不存在”我们自己的错误处理之前阻止了它。

标签: typo3 url-routing extbase typo3-10.x typo3-11.x


【解决方案1】:

我不能说为什么,但是如果您将每个案例定义为自己的路线,它就会起作用:

  • 一类
  • 两个类别
  • 三个类别
  • 产品名称

...以及没有任何给定参数(或默认值!)的默认情况:

routeEnhancers:
  Werbemittelshop:
    type: Extbase
    extension: Mwwerbemittelshop
    plugin: Mwwerbemittelshop
    routes:
      -
        routePath: '/{productname}'
        _controller: 'MwWsCategories::product'
        _arguments:
          productname: mwWsProduct
      -
        routePath: '/{categoryname}'
        _controller: 'MwWsCategories::category'
        _arguments:
          categoryname: mwWsCategory
      -
        routePath: '/{categoryname}/{categoryname2}'
        _controller: 'MwWsCategories::category'
        _arguments:
          categoryname: mwWsCategory
          categoryname2: mwWsCategory2
      -
        routePath: '/{categoryname}/{categoryname2}/{categoryname3}'
        _controller: 'MwWsCategories::category'
        _arguments:
          categoryname: mwWsCategory
          categoryname2: mwWsCategory2
          categoryname3: mwWsCategory3
    defaultController: 'MwWsCategories::category'
    aspects:
      categoryname:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug
      categoryname2:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug
      categoryname3:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
        routeFieldName: slug
      productname:
        type: PersistedAliasMapper
        tableName: tx_mwwerbemittelshop_domain_model_mwwsproducts
        routeFieldName: slug

【讨论】:

  • 我不得不再次降级系统,这样我才能处理剩下的待办事项。我需要几天的时间来尝试,但我肯定会尝试并给你我的反馈。已经谢谢你了!
猜你喜欢
  • 2012-10-11
  • 1970-01-01
  • 2014-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-28
  • 1970-01-01
  • 2018-02-04
相关资源
最近更新 更多