By default symfony actions will always try to load a template. By
sending that return sfView::NONE you are overriding that default
behaviour and telling symfony that in fact you don't want any template
just the response generated in the sfResponse object sent back

On Thu, Apr 29, 2010 at 9:41 AM, NOOVEO - Christophe Brun
<[email protected]> 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.
>
> 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 : [email protected] [mailto:[email protected]] 
> De la part de Gareth McCumskey
> Envoyé : jeudi 29 avril 2010 08:53
> À : [email protected]
> 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 <[email protected]> 
> 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", "[email protected]", "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 [email protected] To
>> unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/symfony-users?hl=en
>>
>
>
>
> --
> Gareth McCumskey
> http://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 [email protected] To 
> unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>



-- 
Gareth McCumskey
http://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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to