Question

I'm using CakePHP 2.4 in and TCPDF to generate invoices.

  • A cronjob checks every day if new invoices shoot be generated.

  • When I access the function via a browser, everything works perfect.

  • When i access the function via the shell, I get an error:

CronjobShell.php:

$cmsoptions = $this->Cmsoption->find('first');
$this->set(compact('data', 'cmsoptions'));
$this->layout = 'pdf';
$this->render(); 

"Call to undefined method CronjobShell::set()"

I understand that the Set option is ginving the problem. But how can I generate the PDF with a Cronjob?

Was it helpful?

Solution

The problem is that AppShell doesn't support view functional by default. So like in similar question, you have to add following:

App::uses('View', 'Core');

$view = new View();
$view->set(compact('data', 'cmsoptions'));
$view->layout = 'pdf';
$pdfContent = $view->render();

And then you can use $pdfContent as content of PDF file with help of file_put_contents('/var/www/new_invoice.pdf', $pdfContent); or similar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top