gazareth
gazareth

Reputation: 1154

CakePHP - render whole page as HTML to attach to email

I have successfully created a report accessed at /controller/report

I now want to create a separate controller method to create this report as an HTML file and email it to designated useds. I have done this but have hit one snag. When the HTML file is rendered, it is only the view element from the /report method - the layout (including the CSS) is not rendered.

Here's the basic structure:

public function email_report() {
    $render = $this->requestAction('/controller/report');
    //$render is then used by fwrite to create a .HTML file, which is then attached to an email
}

public function report() {
    //yada yada
    //render in report layout rather than default
    $this->render('report', 'reports');
}

So the problem is that $render only contains the view stuff, not the stuff from my "reports" layout. What do I need to do to get the layout in my HTML file as well?

I could put all of the HTML in the view but I would like to create other reports using the same layout in future and would like to avoid repetition.

Upvotes: 0

Views: 561

Answers (1)

yomexzo
yomexzo

Reputation: 685

use the following instead. Note the extra array argument passed to the function

bare indicates whether or not to include layout. setting it to 0 i.e false forces it to include layout. Including return sets requested to 1. requested indicates whether request is from requestAction or not.

Visit http://book.cakephp.org/2.0/en/controllers/request-response.html and http://book.cakephp.org/2.0/en/controllers.html for reference

$this->requestAction('/controller/report', array('return', 'bare' => 0));

Upvotes: 1

Related Questions