CakePHP 2.xx rendering view of original method after saving pdf through second method

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

CakePHP 2.xx rendering view of original method after saving pdf through second method

Dave Edwards

I am using CakePHP 2.xx and the following component - to render pdf's.

I have 2 Controller methods, the first method request_pdf calls a second method send_pdf in the same Controller. The second method creates and saves a pdf to file, and will then email the pdf (but for simplicity I have omitted this part of the code).

Once the second method send_pdf finishes creating the pdf control should be passed back to the first method request_pdf where it should then render on screen the view file in view/Documents/request_pdf.

The pdf correctly saves to the TMP directory, BUT when request_pdf renders in the browser, it renders the pdf on screen. The saving of the pdf seems to interfere with the rendering of the view.

Here is my Controller code

App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');

class DocumentsController extends AppController {

public $components = array('Mpdf');

// --------------------------------------------------
// beforeFilter
// --------------------------------------------------

public function beforeFilter()

function request_pdf()

// have also tried this as described by the author of Mpdf component
// $result = $this->requestAction(array('action' => 'send_pdf/'), array('return', 'bare' => false));

function send_pdf()
->layout = null;

= $this->render('send_pdf');

= $response->body();
->Mpdf->Output(TMP.'requested_pdf.pdf', 'F');

// have also tried this
// $this->Mpdf->setFilename(TMP.'requested_pdf.pdf');
// $this->Mpdf->setOutput('F');

I'm sure that it is something simple that I'm over looking here regarding the rendering of the original view, but I can't work it out.

I have also tried calling different methods in both the first and second methods without success,


If I remove $this->layout = null from send_pdf then I get both the pdf AND view from request_pdfrendered on the screen overlaying each other.

All help appreciated.

Like Us on FaceBook
Find us on Twitter

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at
For more options, visit