FriendsOfCake/CakePdf

Force download in Controller

JulyanoF opened this issue · 3 comments

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 but I already set download param do true

ADmad commented

Download and redirect together is not possible with http.