dompdf - how can I save PdfModel to file in Zend Framework 2? -
i use zf2 , dompdfmodule\view\model\pdfmodel generate pdf. when shown view fine, cannot find out how save file (in code, without asking user download). have code this:
use dompdfmodule\view\model\pdfmodel; $viewmodel = new pdfmodel($variables); $viewmodel->settemplate('pos/stocklist/' . $type); $viewmodel->setoption('papersize', 'a4'); $viewmodel->setoption('paperorientation', 'portrait'); $viewmodel->setoption('filename', 'stock.pdf');
i tried in way, render method not exist:
$output = $viewmodel->render(); $handle = fopen($file_path.directory_separator.$file_name , 'w'); fwrite( $handle,$output ); fclose( $handle );
appreciate help.
an example @ project's github readme page shows $viewmodel
being returned controller action. also, filename
option you've specified should force file downloaded rather displayed within browser.
the author has implemented view strategy/renderer creates actual dompdf object , automatically renders view model you, similar existing zf2 behavior, don't have short-circuit mvc lifecycle.
Comments
Post a Comment