Skip to content

Instantly share code, notes, and snippets.

@xphere
Last active January 27, 2016 15:21
Show Gist options
  • Save xphere/9874b52265ac51b6eaa6 to your computer and use it in GitHub Desktop.
Save xphere/9874b52265ac51b6eaa6 to your computer and use it in GitHub Desktop.
Some controller helpers
<?php
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
trait MakeDownloadable
{
/**
* @param Response $response
* @param string $filename
* @param string $contentType
*
* @return Response
*/
private function makeDownloadable(Response $response, $filename, $contentType)
{
$disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$filename
);
$response->headers->add([
'Content-Type' => $contentType,
'Content-Disposition' => $disposition,
]);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment