Generate multiple PDFs

In CakePHP2 we had an form that would print multiple PDFs for a list of people

The form had a few fields to complete and a list of members, when you checked a member and ran the form, it would generate individual PDFs. These were written to the filesystem and at the end, zipped up and downloaded to the user’s computer.

Under the cover it used RequestAction to call a function, however this option I believe is no longer available in CakePHP4.

What would be the recommended method these days? I’ve read a few stackoverflow posts recommending dependency injection / services

1 Like

Just services, that each of them in a method just calls

$request = new ServerRequest(['params' => ['_ext' => 'pdf']]);
$view = new PdfView($request);
$view->set('salesOrder', $salesOrder);
$content = $view->render('/SalesOrders/pdf/view');

etc

You can still have the same controller actions as “preview” then for example, while the actual business logic calls these service wrappers.

1 Like