Force download in Controller
JulyanoF opened this issue · 3 comments
JulyanoF commented
How can I force download calling my pdf method by another method? If I access method directly, it's downloading normally.
Basically, I'm trying to redirect after download file or redirect and download file..
I'm trying something like this:
public function test(){
$this->myPdf('test');
}
public function myPdf($name){
$this->RequestHandler->renderAs($this, 'pdf', ['attachment' => $name . '.pdf']);
}
I already tried:
public function test(){
return $this->redirect(['action' => 'myPdf', 'test']);
}
public function myPdf($name){
$this->RequestHandler->renderAs($this, 'pdf', ['attachment' => $name . '.pdf']);
return $this->redirect(['action' => 'index']);
}
AND
public function test(){
$this->myPdf('test');
}
public function myPdf($name){
$this->RequestHandler->renderAs($this, 'pdf', ['attachment' => $name . '.pdf']);
return $this->redirect(['action' => 'index']);
}
I know that myPdf function is called (I debugged) but file is not downloading.
My bootstrap.php:
Plugin::load('CakePdf', ['bootstrap' => true]);
Configure::write('CakePdf', [
'engine' => 'CakePdf.DomPdf',
'download' => false
]);
And routes.php:
Router::extensions(['pdf']);
destinydriven commented
…
On Thu, May 10, 2018 at 10:37 PM, JulyanoF ***@***.***> wrote:
How can I force download calling my pdf method by another method? If I
access method directly, it's downloading normally.
I'm trying something like this:
public function test(){
$this->myPdf('test');
}
public function myPdf($name){
$this->RequestHandler->renderAs($this, 'pdf', ['attachment' => $name . '.pdf']);
}
I know that myPdf function is called (I debugged) but file is not
downloading.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#259>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAV3AQDm9beFisOfWSKXy7p0t70PkJW_ks5txPlagaJpZM4T60XW>
.
--
With the spoon of determination in the hand of faith, you can carve a
tunnel of hope in the mountain of despair.
JulyanoF commented
@destinydriven but I already set download param do true
ADmad commented
Download and redirect together is not possible with http.