Rick
Rick

Reputation: 698

CakePHP - Calling an action in the background

I created a nice little function that creates an invoice and saves it as a PDF on my server, called create_invoice().

I would like to use that action in a different action in the same controller. What it needs to do, is show the invoice as HTML on the screen, while saving the PDF in the background. The users should not notice this.

I've looked at setAction and requestAction, but it's not really what I need. Any suggestions?

Cheers

Upvotes: 0

Views: 151

Answers (1)

dogmatic69
dogmatic69

Reputation: 7575

You are having problems doing this because its wrong. You should build this code as a lib, that way you can run the invoices from anywhere.

MyInvoiceLib::generate($data);

For example you may want to later do this in a shell through crons.

See here for a good plugin to render pdfs, note there are no controllers in it.

Upvotes: 1

Related Questions