我正在尝试为 TYPO3 扩展 web2pdf 设置 RouteEnhacer 以将 https://example.com/subpage/?tx_web2pdf_pi1[action]=generatePdfLink&tx_web2pdf_pi1[argument]=printPage&tx_web2pdf_pi1[controller]=Pdf&cHash=123456789 之类的 URL 重写为 https://example.com/subpage/pdf/。
通过使用……
routeEnhancers:
Web2pdf:
type: Plugin
routePath: '/pdf/{argument}'
namespace: 'tx_web2pdf_pi1'
aspects:
argument:
type: StaticValueMapper
map:
1: printPage
...我已经得到了更短的 URL:
是否可以进一步优化路由以便我获得所需的短 URL?
我怀疑 Extbase 路由增强器会更好,但我的尝试都失败了,也没有进行重写。
最佳答案
IMO 不需要映射 controller 和 action,因为这些是默认参数,由适当配置的增强器自动处理。唯一需要映射的(非标准/自定义)参数是 tx_web2pdf_pi1[argument]。
这里是 extbase 路由增强器,它生成/your/subpage/pdf:
routeEnhancers:
Pdf:
type: Extbase
extension: Web2pdf
plugin: Pi1
routes:
- routePath: '/{your_argument_replacement}'
_controller: 'Pdf::generatePdfLink'
_arguments:
your_argument_replacement: 'argument'
aspects:
argument:
type: StaticValueMapper
map:
pdf: 'printPage'
使用以下链接进行测试,由 fluid viewhelper 呈现:
<f:link.action action="generatePdfLink"
controller="Pdf"
extensionName="Web2pdf"
arguments="{argument:'printPage'}">PDF</f:link.action>
关于routes - 用于扩展 web2pdf 的 TYPO3 RouteEnhancer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72940000/