Skip to content

Instantly share code, notes, and snippets.

@malteo
Created April 4, 2013 14:14
Show Gist options
  • Save malteo/5310697 to your computer and use it in GitHub Desktop.
Save malteo/5310697 to your computer and use it in GitHub Desktop.
anche PHP ha i suoi momenti
$app->get('/admin/print/{course_id}/{generated}', function ($course_id, $generated) use ($app) {
$query = $app['idiorm']->getTable('keys')
->select('code')
->where('course_id', $course_id)
->where('generated', $generated);
$stream = function () use ($query) {
$out = fopen('php://output', 'w');
foreach ($query->find_array() as $key) {
fputcsv($out, $key);
}
fclose($out);
};
return $app->stream($stream, 200, array(
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment; filename="Course'.$course_id.'_'.$generated.'.csv"'
));
})
->bind('print');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment