2014-10-07 142 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