title: Calling controller from twig
body: <p>I'm currently discovering Symfony, and I have some trouble calling a function from one of my controllers. </p>
  
  <pre><code>&gt; class CsvController extends Controller {
  
  public function generateCsvAction(){
      $conn=$this-&gt;get('database_connection')
  
      $results=$conn-&gt;query("
      SELECT *
      FROM external_attribute;
      ")
  
      $response=new StreamedResponse();
      $response-&gt;setCallback(function() use($results)){
          $handle=fopen("/home/basile/Documents/backend/src/CampaignBundle/Controller/test.csv","w+");
          fputcsv($handle,array('test1
              test2,
              test3,
              test4,
              test5,
              test6,
              test7,
              test8')
          ),';');
      }
  
      fclose($handle);
  }
  
  $response-&gt;setStatusCode(200);
  $response-&gt;headers-&gt;set('Content-Type', 'text/csv; charset=utf-8');
  $response-&gt;headers-&gt;set('Content-Disposition','attachment; filename="test.csv"');      
  return $response;  
  </code></pre>
  
  <p>}</p>
  
  <p>I already set everything in my routing.yml : </p>
  
  <pre><code>export_csv:
  defaults: { _controller: CampaignBundle:Controller:CsvController.php }
  </code></pre>
  
  <p>and now I want to call it from a button in a file named "index.html.twig" . I know we can render from the controller some variables and array, but here i directly want to  call a function</p>
  
  <p>If you have any kind of idea, it would be very welcomed !</p>