[英]Optional routes with routeEnhancers in TYPO3
I am struggling to get the following routes of a TYPO3 plugin to work:我正在努力使 TYPO3 插件的以下路径正常工作:
example.com/page/
-> not working! example.com/page/
-> 不工作!example.com/page/az/a/
-> working example.com/page/az/a/
-> 工作example.com/page/az/a/more/2/
-> working example.com/page/az/a/more/2/
-> 工作example.com/page/page-2/
-> not working! example.com/page/page-2/
-> 不工作! The URI looks like this: URI 如下所示:
example.com/page?tx_myextension_list[controller]=MyController&tx_myextension_list[currentPage]=2&tx_myextension_list[selectedLetter]=&cHash=6258466362eee8ea43be8634002c883f
My error:我的错误:
Symfony\\Component\\Routing\\Exception\\InvalidParameterException: Parameter "uf29714be1a983f4b1a864d48e1b6ae" for route "tx_myextension_list_1" must match "[a-zA-Z]{1}" ("" given) to generate a corresponding URL.
Symfony\\Component\\Routing\\Exception\\InvalidParameterException: 路由 "tx_myextension_list_1" 的参数 "uf29714be1a983f4b1a864d48e1b6ae" 必须匹配 "[a-zA-Z]{1}" ("" given) 以生成相应的 URL。
If I remove the empty parameter tx_myextension_list[selectedLetter]
URL 1 is working, but URL 3 looks like this URL 4 and behaves like this.如果我删除空参数
tx_myextension_list[selectedLetter]
URL 1 正在工作,但 URL 3 看起来像这个 URL 4 并且表现得像这样。
This is my configuration:这是我的配置:
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
I think you just forgot a "/" at:我想你只是忘记了一个“/”:
routePath: 'page-{page}'
_controller: 'MyController::list'
_arguments:
page: 'currentPage'
Thus "example.com/page/page-2/" wong get generated.这样就生成了“example.com/page/page-2/”wong。
Also have a look at the documentation for the requirements: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Routing/AdvancedRoutingConfiguration.html#aspect-precedence You dont need to add the requirements for the letters if you are using a map for them.另请查看要求的文档: https : //docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Routing/AdvancedRoutingConfiguration.html#aspect-precedence你不需要如果您使用地图,请添加对字母的要求。
Another problem should be the default value for your letter.另一个问题应该是您的信件的默认值。 Because an empty string isnt matching your requirements/map.
因为空字符串不符合您的要求/地图。
Thats what the error is telling you:这就是错误告诉你的:
must match "[a-zA-Z]{1}" ("" given)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.