2014-10-07 59 views
0

我有这样的路线:路由与Laravel公共文件夹中的文件4

Route::any("/operations/xml", array("as"=>"operations.xml", "uses"=>"[email protected]")); 

我的控制器产生的公共文件夹中保存一个xml:

OperationsController.php:

public function generateXml(){ 

    $doc = new DomDocument("1.0", "UTF-8"); 
    $doc->formatOutput = true; 

    //I add my stuff inside de xml from the database here... 

    $doc->save("xml/test.xml"); 

} 

但我需要的是,当我导航到路线http://example.com/operations/xml我将能够下载xml。我怎样才能做到这一点?

回答

1

将以下内容添加到该函数的末尾。

return Response::download(public_path() . "xml/test.xml", 'name.xml', array('Content-Type' => 'application/xml')); 

参数是;

  • 1st是文件路径。
  • 2nd是文件的名称。
  • 第3个是标题。
+0

完美,谢谢! – 2014-10-07 15:36:46

相关问题