On Apr 29, 3:41 am, "NOOVEO - Christophe Brun" <c.b...@nooveo.fr> wrote: > @Eno : Yes, I tried commenting only some of thse lines instead of all three > but it still goes in error. > @Gareth : Useful link, I was not aware of this function, thanks ! But here, > I cant' use that because I want to send the data to the browser.
I'm dealing with a similar issue, though I'm trying to let symfony handle the header for 'text/csv' for me by trying to configure a new 'csv' :sf_format in factories.yml. Anyway, you actually can use fputcsv to dump directly to a browser using a stream $handle = fopen('php://output', 'w'); fputcsv($handle, array(....)); fclose($handle); > > After some additional inquiries, I eventually discovered on a blog some > workaround by adding one line at the end of the execute method : > > return sfView::NONE; > > That's cool, but I still don't understand why it fails without this line. > After all, when I am sending xml data, I am actually using an action without > this special line of code, I am using templates and my browser does receive a > correct XML input, not an HTML one. Why does it work with xml and not with > csv ? Is it related to the way the route is declared, or something else ? > > -----Message d'origine----- > De : symfony-users@googlegroups.com [mailto:symfony-us...@googlegroups.com] > De la part de Gareth McCumskey > Envoyé : jeudi 29 avril 2010 08:53 > À : symfony-users@googlegroups.com > Objet : Re: [symfony-users] Exporting data to CSV (+Doctrine) > > Why even use a template? > > http://www.php.net/manual/en/function.fputcsv.php > > On Wed, Apr 28, 2010 at 4:15 PM, NOOVEO - Christophe Brun <c.b...@nooveo.fr> > wrote: > > > > > Ladies & gentlemen, > > > My client wants a .csv export with a simple list of entries, namely : > > the list of the web users who registered to his newsletter. > > I tried to add a ListCsvExport button in the backend and the > > appropriate method in the action, with no success. > > > A simple template for tests : > > listCsvExportSuccess.php : > > <?php > > echo implode("\t", $headers), "\n"; > > foreach($lines as $l) { > > echo implode("\t", $l, "\n"); > > } > > ?> > > and the method : > > public function executeListCsvReport(sfWebRequest $request) { > > $response = $this->getResponse(); > > $response->clearHttpHeaders(); > > $response->setContentType('application/vnd.ms-excel'); > > $response->setHttpHeader('Content-disposition', "attachment; > > filename=newsletter_".date("YmdHis").".csv"); > > $this->layout(false); > > $this->setTemplate('listCsvReportSuccess'); > > > $this->headers = array( > > "Nom", "Email", "Actif", "Utilisateur enregistré ?" > > ); > > > $this->lines = array(); > > $this->lines[] = array("my name", "c...@tt.net", "1", "0"); } This > > code results in my browser displaying an error : File not found. > > Firefox cannot find the file at the url > >http://127.0.0.1:8081/users_dev.php/newsletter/ListCsvReport/action > > > OTOH, if I comment some lines in my method : > > // $response->clearHttpHeaders(); > > // $this->layout(false); > > // $this->setTemplate('listCsvReportSuccess'); > > my browser downloads a .csv file. Unfortunately, the file displays > > uncool data such as HTML and PHP code but not a single line of my > > template, except the cryptic <td > > title='C:\wamp\www\Compagnie\apps\users\modules\newsletter\templates\listCsvReportSuccess.php' > > bgcolor='#eeeeec'>..\listCsvReportSuccess.php<b>:</b>4</td></tr> > > > Obviously, I'm missing some elephant. Can you point me to the right > > direction ? > > > -- > > If you want to report a vulnerability issue on symfony, please send it > > to security at symfony-project.com > > > You received this message because you are subscribed to the Google > > Groups "symfony users" group. > > To post to this group, send email to symfony-users@googlegroups.com To > > unsubscribe from this group, send email to > > symfony-users+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/symfony-users?hl=en > > -- > Gareth McCumskeyhttp://garethmccumskey.blogspot.com > twitter: @garethmcc > > -- > If you want to report a vulnerability issue on symfony, please send it to > security at symfony-project.com > > You received this message because you are subscribed to the Google Groups > "symfony users" group. > To post to this group, send email to symfony-users@googlegroups.com To > unsubscribe from this group, send email to > symfony-users+unsubscr...@googlegroups.com > For more options, visit this group > athttp://groups.google.com/group/symfony-users?hl=en > > -- > If you want to report a vulnerability issue on symfony, please send it to > security at symfony-project.com > > You received this message because you are subscribed to the Google > Groups "symfony users" group. > To post to this group, send email to symfony-users@googlegroups.com > To unsubscribe from this group, send email to > symfony-users+unsubscr...@googlegroups.com > For more options, visit this group > athttp://groups.google.com/group/symfony-users?hl=en -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en