【发布时间】: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