Tuesday, October 26, 2010

Download some plain text

Hi everybody

I want to give my users the possibility to download the content of the
model IniFile's field "text" as plain text.

I came up with the following solution:

function exportIniFile() {
$iniFile = $this->IniFile->find($this->params['named']['id']);
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=
\"{$iniFile['IniFile']['user_name']}.ini\"");
echo $iniFile['IniFile']['text'];
die;
}

This works, but I suspect that it's not the very best solution,
because I have to use a die() statement to break code execution,
because otherwise the layout and stuff would be appended to the
IniFile's text. Is there a better way? I tried $this->layout = false,
but this didn't work...

Thanks a lot
Josh

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: