gdm
gdm

Reputation: 7930

Render Custom PDF From Custom Html

I have a list of products in my DB. For every product I have to generate a PDF (the receipt) whose template/layout differs from others. I was thinking to put the html layout/template in a column of the products DB table. But how to render it in CakePhp? I have to render some variables...

Upvotes: 0

Views: 84

Answers (1)

drmonkeyninja
drmonkeyninja

Reputation: 8540

I've tackled a similar issue where I've had a Page model where individual pages had vastly different layouts.

I would create View templates, in your View folder, for each variant layout for your products and then have a pdf_view_template column in your database that stores the template to use. Then in your ProductsController set the view:-

if (!empty($data['Product']['pdf_view_template'])) {
    $this->view = $data['Product']['pdf_view_template'];
}

This would allow templates to be reusable as well as giving you the ability to have a default template to fall back on. It also avoids you having to store loads of templating data in the database.

This seems like a more Cake way of doing this.

Upvotes: 1

Related Questions