Cakephp:将字符串变量下载为文件

Is it possible to do download a string variable in my code as a file with cakephp ?

For example:

$myString = "value1;value2;value3 1;2;3";

I want to download the string $myString as a csv file without saving it on my server. I just want the user to be able to download the string as a file.

If you have regular php solutions, It can do the job but I prefer to use CakePHP.

Thanks for your help,

Antoine

You have tagged this question with cakephp 2.0

As burzum points out they have an example exactly for this use case of yours here

Sending a string as a file

Work in Cakephp 3.7

$body = $this->response->getBody();
$body->write('"your", "text"');

$body = $this->response->withBody($body)->withCharset('windows-1251')->withType('text/csv');

return $this->response->withDownload('yourFileName.csv');