Skip to content

Instantly share code, notes, and snippets.

@jaimeperez
Created September 24, 2019 10:18
Show Gist options
  • Select an option

  • Save jaimeperez/d53874daa52bf42ac712aa368643f338 to your computer and use it in GitHub Desktop.

Select an option

Save jaimeperez/d53874daa52bf42ac712aa368643f338 to your computer and use it in GitHub Desktop.
How to return different responses from a controller
// if the response is XML:
$response = new \Symfony\Component\HttpFoundation\Response();
$response->setContent($xml);
return $response;
// if the response is a twig template:
$template = new \SimpleSAML\XHTML\Template('whatever.twig');
$template->data = ['foo' => 'bar'];
return $template;
// finally, if the response is an old PHP template:
$template = new \SimpleSAML\XHTML\Template('whatever.tpl.php');
$template->data = ['foo' => 'bar'];
return new \Symfony\Component\HttpFoundation\StreamedResponse([$template, 'show']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment