forms - symfony 2, for download file request return empty response with flash message set -
i have link on web form, points file download action.
public function downloaddataaction($data_id) { //get data database , create zip file ($fzip) data $content = file_get_contents($fzip); $filename = 'mydata_' . $data_id . '.zip'; $headers = array( 'content-type' => 'application/zip', 'content-disposition' => "attachment; filename=" . urlencode($filename), ); return new response($content, 200, $headers); }
the above action works expected; zip file downloaded, when there's data specified id, , original web form stays was, without change or refresh. don't know response return, when there no data found in database. ideally, i'd set flash message, without refresh, flash won't seen on form, , refresh destroy entries made user, if there entries made user, before link clicked. should do?
following code generate refresh setting flash message
if (!isset($fzip)) { $this->get('session')->getflashbag()->add('notice','notice message content'); return $this->redirect($this->generateurl('_route_name')); }
but can render twig display message
if (!isset($fzip)) { return $this->render('@acmedemo/default/index.html.twig', array('msg' => 'message content')); }
Comments
Post a Comment