Skip to content

Instantly share code, notes, and snippets.

@MayMeow
Last active January 15, 2022 08:34
Show Gist options
  • Save MayMeow/c2ff4cc882d0a7923d1546b0092e30b1 to your computer and use it in GitHub Desktop.
Save MayMeow/c2ff4cc882d0a7923d1546b0092e30b1 to your computer and use it in GitHub Desktop.
Cakephp Send string as file
<?php
public function sendIcs()
{
$icsString = $this->Calendars->generateIcs();
$response = $this->response;
// Inject string content into response body
$response = $response->withStringBody($icsString);
$response = $response->withType('ics');
// Optionally force file download
$response = $response->withDownload('filename_for_download.ics');
// Return response object to prevent controller from trying to render
// a view.
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment