weixin_33738578 2019-05-14 10:10 采纳率: 0%
浏览 41

Typo3 9.x Ajax调用

Configuration about a single route for ajax call: getamministrazioni.json

I tried to change configuration site as follow:

...


    routeEnhancers:
      News:
        type: Extbase
        extension: News
        plugin: Pi1
        routes:
          -
            routePath: '/{news-title}'
            _controller: 'News::detail'
            _arguments:
              news-title: news
        aspects:
          news-title:
            type: PersistedAliasMapper
            tableName: tx_news_domain_model_news
            routeFieldName: path_segment
      PageTypeSuffix:
        type: PageType
        default: .html
        map:
          .html: 0
          getamministrazioni.json: 1035343

    errorHandling: {  }
    routes: {  }
...

And in setup.typoscript i have:

GetAmministrazioni = PAGE
GetAmministrazioni {
typeNum = 1035343
config {
    disableAllHeaderCode = 1
    debug = 0
    no_cache = 1
    additionalHeaders {
      10 {
        header = Content-Type: application/json
        replace = 1
      }
    }
}
 10 < tt_content.list.20.my_controller_getamministrazioni

}

It works but for all pages.

  1. /home/getamministrazioni.json
  2. /page1/getamministrazioni.json

etc.. etc..

I want a single route from root '/getamministrazioni.json

how i can do that?

  • 写回答

2条回答 默认 最新

  • weixin_33701251 2019-05-14 21:31
    关注

    There is a possibility to limit the routing to specific page ids:

    limitToPages: 1
    

    But this will limit your whole mapping configuration to page id 1, also the .html suffix (which you don't want to, I guess).

    Unfortunately, it is currently not possible to create multiple Route Enhancers with the same name, like in the following, non-working example:

    PageTypeSuffix:
      type: PageType
      map:
        .html: 0
    PageTypeSuffix:
      type: PageType
      limitToPages: 1
      map:
        sitemap.xml: 1533906435
    

    Two possible workarounds:

    1. Create your own RouteEnhancer, which just extends TYPO3\CMS\Core\Routing\Enhancer\PageTypeDecorator to allow a different name (see custom enhancers)

    2. Redirect your json page type to an error page, if page id is not 0 (no routing neccessary, as TypoScript avoids delivering of this page type)

      [getTSFE().id != 1] seo_sitemap.config { additionalHeaders.10 { header = Location: /error.html } } [END]

    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵