on my sympfony webapp should simply search a database for the right file and present a download link/button to get the file. But i only have a variable with the content of the file i want to be downloadable. So i think i cant use href because i have no file just a string.
The search Bar in my index.html.twig like this
<div id="main" class="search"> <p>Please insert the corresponding mail to find the S/MIME-Zertificat</p> <div class="form-container"> {% if smimekey == false %} <form action="{{path('search')}}" method="get"> <input type="text" class="email" name="sbar" placeholder="enter email ..." /> <input type="submit" value="search" class="submit"/> </form> {% elseif smimekey=="NULL" %} <form action="{{path('search')}}" method="get"> <input type="text" class="email" name="sbar" placeholder="No such Email or Zertifikat found" /> <input type="submit" value="search" class="submit"/> </form> {% elseif smimekey!="NULL" %} <form action="{{path('search')}}" method="get"> <input type="text" class="email" name="sbar" placeholder="enter email ..." /> <input type="submit" value="search" class="submit"/> ######### DOWNLOAD BUTTON / link ############### </form> {% endif %} </div> </div>
So this index.html.twig has 3 possible designs
- first time visit when no smimekey is selected
- no smimekey was found
- and a smimekey was found and should be downloadable
my php file wich goes into the db and searches for the stuff looks like this:
/**
* @Route("/search", name="search")
*/
public function searchAction(Request $request)
{
$sbar=$_GET['sbar'];
if (filter_var($sbar, FILTER_VALIDATE_EMAIL)) {
$smimekey = $this->getDoctrine()
->getRepository('AppBundle:Zertifikat')
->findOneByEmail($sbar);
$smimekey=stream_get_contents($smimekey->getSmimekey());
);
}
else{$smimekey="";}
if (!$smimekey) {
$smimekey="NULL";
}
return $this->render('default/index.html.twig', array(
'email'=>$sbar,'smimekey'=>$smimekey, 'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..'),
));
}
so now that i have the smimekey wich was saved as a Blob in the DB is now a simple string in the variable smimekey and i return it to my index.html.twig
I did not find any good methods to download a "generated" file with my variable as content.