routes - 用于扩展 web2pdf 的 TYPO3 RouteEnhancer

标签 routes typo3 extbase typo3-10.x typo3-11.x

我正在尝试为 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:

https://example.com/subpage/pdf/1/?tx_web2pdf_pi1[action]=generatePdfLink&tx_web2pdf_pi1[controller]=Pdf&cHash=123456789

是否可以进一步优化路由以便我获得所需的短 URL?

我怀疑 Extbase 路由增强器会更好,但我的尝试都失败了,也没有进行重写。

最佳答案

IMO 不需要映射 controlleraction,因为这些是默认参数,由适当配置的增强器自动处理。唯一需要映射的(非标准/自定义)参数是 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/

相关文章:

routes - 通过 angularjs 中的路由进行重定向

redirect - 这段代码中我的 $this->redirect(...) 调用有什么问题?

Typo3 v10 中的 Ajax 请求 : Calling controller action via typeNum

session - TYPO3/Extbase - 切换到另一个 fe_user - 最后回到原始用户

typo3 - 通过子对象对元素进行排序

linux - 如何从 PPP 接口(interface)转发数据包?

c# - routes.MapPageRoute 不适用于点?

c# - MVC - 注册路由

namespaces - 未找到 ViewHelper

typo3 - 在钩子(Hook) processDatamap_afterDatabaseOperations 中获取新记录的 uid