doumen1883 2014-04-03 06:08
浏览 39
已采纳

在CakePHP中为XML和JSON以外的文件类型创建数据视图

How can I export data from a CakePHP 2.4 app as KML, not just XML and JSON?

This is what I've been trying:

1: I created a simple controller action, download, to find all data in my model:

$this->set('posts', $this->Post->find('all'));

2: I addeded the file type in routes.php:

Router::parseExtensions('json', 'xml', 'kml', 'csv');

3: I created a folder for my data view file type:

/app/View/Post/kml

4: I created a view, download.ctp, which manually echos out the XML tags for the KML file.

Now comes the problem: When I place this view file under /app/View/Post/xml, visiting /posts/download.xml creates a valid KML document I can open in Google Earth, albeit with an .XML extension. When I place the file under /app/View/Post/kml, and visit /posts/download.kml, it throws an error: View file "/home/public/app/View/Themed/Cakestrap/Posts/download.ctp" is missing.

I tried copying my view to the above location, but that just echos the XML into my standard layout. What's the proper way to create data views for filetypes other than XML and JSON?

  • 写回答

1条回答 默认 最新

  • douben7260 2014-04-04 20:03
    关注

    Saddly KML does not have a mime type recognized in servers vide Google. So when you add it to Router::ParseExtensions(...) Cake can't see that extension and won't try to access your download.ctp inside kml folder.

    You have two alternatives to setup this to work:

    • Change server settings in order to it recognize the extension Google Doc.
    • Try to call render manually like this:

      <?php
      $this->response->type("application/vnd.google-earth.kml+xml");
      $this->render('kml/download.ctp', 'xml');
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?