2014-10-07 4 views
0

는이 같은 경로가 있습니다라우팅 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')); 

매개 변수는 다음과 같습니다.

  • 첫 번째는 파일 경로입니다.
  • 2nd는 파일 이름입니다.
  • 세 번째는 헤더입니다.
+0

완벽한 감사합니다. –