2013-12-18 40 views
0

我已經成功地創建在/控制器訪問的報告/報告CakePHP的 - 使整個頁面爲HTML附加到電子郵件

我現在想創建一個單獨的控制器方法來創建此報告爲HTML文件,並通過電子郵件發送到指定用途。我已經做到了這一點,但碰到了一個障礙。當HTML文件被渲染時,它只是來自/ report方法的視圖元素 - 佈局(包括CSS)不會被渲染。

這裏的基本結構:

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'); 
} 

所以問題是,$僅渲染包含視圖的東西,而不是東西從我的「報告」的佈局。我需要做些什麼才能在我的HTML文件中獲得佈局?

我可以把所有的HTML放在視圖中,但我想在將來使用相同的佈局創建其他報告,並希望避免重複。

+0

您是否嘗試過設置佈局:$ this-> Layout ='default'; – Dave

+0

我剛試過 - 它不起作用。 – gazareth

+0

您是否使用EmailComponent? –

回答

1

改爲使用以下內容。請注意傳遞給函數的額外數組參數

bare指示是否包含佈局。將其設置爲0,即false強制它包含佈局。包括returnrequested1requested指示請求是否來自requestAction。

http://book.cakephp.org/2.0/en/controllers/request-response.html訪問和http://book.cakephp.org/2.0/en/controllers.html參考

$這 - > requestAction( '/控制器/報告',陣列( '返回', '裸'=> 0));

+0

謝謝,這個作品很棒。我實際上正在閱讀requestAction,但我一定是在文檔的錯誤部分,因爲我沒有看到任何關於'裸'。 – gazareth