This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Help with view config

This is for discussion, mainly on 1.x but there's some 2.x topics here too.

Help with view config

by White Hat World » Sat Aug 16, 2014 10:27 am

Hello,

I'm trying to produce a csv export file by changing the http_meta config as described in the View Configuration chapter of the documentation.

I have a view called doExport with a corresponding doExportSuccess.php page and a executeDoExport action.

I've created a view.yml file with an all: section and can change stuff there and see the effects. This is in a config folder in the relevant module.

So I assume I need to add:

doExport:
http_metas:
content-type: text/html

has_layout: false

I've tried all sorts of indentation and positionings but can't seem to get the changes to take.

view.yml is attached.

Can anyone please tell me what I'm doing wrong?

Thanks :)
White Hat World
Junior Member
 
Posts: 1
Joined: Sat Aug 16, 2014 10:21 am

Re: Help with view config

by mickburkesnr » Wed Oct 22, 2014 5:37 pm

I'm not sure what you're doing really with what you've described.

This is how I've achieved it below. I use the one controller with a twig file and it works perfectly.

Controller:
Code: Select all
<?php

namespace Acme\YourBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

class DownloadController extends Controller
{

    public function dodownloadAction(Request $request)
    {   
      // Do your magical Database/Data stuff here!

      $data = $databasemagic->getResult();

      // Create CSV and Stick Data In It
      $filename = "download_".date("Y_m_d_His").".csv";
      $response = new Response();
      $response = $this->render('DefaultBundle:Download:downloadedcsv.html.twig', array('data' => $data));
      $response->headers->set('Content-Type', 'text/csv');
      $response->headers->set('Content-Disposition', 'attachment; filename='.$filename.'');

      return $response;

    }


View.twig:
Code: Select all
Row_Data_1,Row_Data_2,Row_Data_3
{% for row in data %}
{{ row.rowofdata1}},{{ row.rowofdata2}},{{ row.rowofdata3}},
{% endfor %}
mickburkesnr
Member
 
Posts: 78
Joined: Mon Aug 22, 2011 12:33 pm
Location: Birmingham, UK