[英]Routing to a file on public folder with Laravel 4
I have a route like this: 我有一条这样的路线:
Route::any("/operations/xml", array("as"=>"operations.xml", "uses"=>"OperationsController@generateXml"));
And my controller generates an xml that saves inside the public folder: 然后我的控制器生成一个保存在公用文件夹内的xml:
OperationsController.php: 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");
}
But what I need is that when I navigate to the route http://example.com/operations/xml I will be able to download the xml. 但是我需要的是,当我导航到http://example.com/operations/xml路径时,将能够下载xml。 How can I do this? 我怎样才能做到这一点?
Add the following to the end of the function. 在函数末尾添加以下内容。
return Response::download(public_path() . "xml/test.xml", 'name.xml', array('Content-Type' => 'application/xml'));
The parameters are; 参数是;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.