Zend framework 1. Physically, the file does not exist, it is created based on database.
Okay so use header?
public function downloadAction()
{
$id = $this->getRequest()->getParam("id");
$optin = new Application_Model_Optin();
//$data = $optin->getCodesFromDownload($id);
$data = array(
array('code' => 12345),
array('code' => 12346),
array('code' => 12347),
array('code' => 12348),
array('code' => 12349)
);
header("Content-type: application/x-download");
header("Content-disposition: attachment; filename=code_" . $id . ".csv");
foreach($data as $item)
{
echo $item['code']."\r\n";
}
die;
}