具有不同参数数量的类型插件的 routeEnhancer
routeEnhancer for type plugin with different number of parameter
我需要能够在我的网址中省略一个或多个参数。例如:
domain.tld/page/my-article/
domain.tld/page/cat/2/my-article
两个网址显示相同的页面。
这适用于第一个变体:
myplugin:
limitToPages:
- 80
type: Plugin
routePath: '/{uid}'
namespace: tx_myext_pi1
requirements:
uid: '[0-9]{1,4}'
aspects:
uid:
type: PersistedAliasMapper
tableName: tx_myext_items
routeFieldName: slug
这是第二个:
myplugin:
limitToPages:
- 80
type: Plugin
routePath: '/cat/{cat}/{uid}'
namespace: tx_myext_pi1
requirements:
cat '[0-9]{1}'
uid: '[0-9]{1,4}'
aspects:
uid:
type: PersistedAliasMapper
tableName: tx_myext_items
routeFieldName: slug
cat:
type: StaticRangeMapper
start: '1'
end: '10'
但我无法让它们同时工作...是否可以定义允许忽略 cat 参数的路由增强器?
谢谢!
经过几个小时的尝试,我找到了(显而易见的)解决方案。实际上,如果您介意我不介意的正确定义顺序,则有很多可能性。
每个 routePath 都属于一个具有不同名称的不同路由增强器。路由路径必须与行首区分开来:
这个有效:
myplugin1:
routePath: '/{id}'
myplugin2:
'/u/{unit}/{id}'
这不是:
myplugin1:
routePath: '/{id}'
myplugin2:
'/{id}/u/{unit}'
因为第一个术语 /{id} 在两个定义中是相同的。
(请记住,由于内容重复,这通常是一个非常糟糕的主意!有时这无关紧要...)
我需要能够在我的网址中省略一个或多个参数。例如:
domain.tld/page/my-article/
domain.tld/page/cat/2/my-article
两个网址显示相同的页面。
这适用于第一个变体:
myplugin:
limitToPages:
- 80
type: Plugin
routePath: '/{uid}'
namespace: tx_myext_pi1
requirements:
uid: '[0-9]{1,4}'
aspects:
uid:
type: PersistedAliasMapper
tableName: tx_myext_items
routeFieldName: slug
这是第二个:
myplugin:
limitToPages:
- 80
type: Plugin
routePath: '/cat/{cat}/{uid}'
namespace: tx_myext_pi1
requirements:
cat '[0-9]{1}'
uid: '[0-9]{1,4}'
aspects:
uid:
type: PersistedAliasMapper
tableName: tx_myext_items
routeFieldName: slug
cat:
type: StaticRangeMapper
start: '1'
end: '10'
但我无法让它们同时工作...是否可以定义允许忽略 cat 参数的路由增强器?
谢谢!
经过几个小时的尝试,我找到了(显而易见的)解决方案。实际上,如果您介意我不介意的正确定义顺序,则有很多可能性。
每个 routePath 都属于一个具有不同名称的不同路由增强器。路由路径必须与行首区分开来:
这个有效:
myplugin1:
routePath: '/{id}'
myplugin2:
'/u/{unit}/{id}'
这不是:
myplugin1:
routePath: '/{id}'
myplugin2:
'/{id}/u/{unit}'
因为第一个术语 /{id} 在两个定义中是相同的。
(请记住,由于内容重复,这通常是一个非常糟糕的主意!有时这无关紧要...)