I need to generate pdf from my view, Im using kartik mPDF,
Controller :
public function actionInvoicesPrint()
{
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE, // leaner size using standard fonts
'content' => $this->renderPartial('view', ['model' => $model, 'mode' => Pdf::MODE_CORE,
'format'=> Pdf::FORMAT_A4,
'orientation'=> Pdf::ORIENT_POTRAIT,
'destination'=> Pdf::DEST_BROWSER]),
]);
return $pdf->render();
}
Getting error Undefined variable: model
. I tried as shown above but getting same error.
View:
public function actionView($id)
{
$searchModel = new InvoicesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$data = Invoices::findOne($id);
return $this->render('view', [
'model' => $this->findModel($id),
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
'data' => $data,
]);
}
Complete Working Solution
IN view to trigger controller
actionInvoicesPrint()
In your actionInvocePrint you don't have a $model assigned
below is a sample of a my working pdf (kartik mPDF like your )
As you can see in this portion of code ..the model is obtained before all and then with this $model is defined a renderPartial with the proper view ..
for passing the $id you action should be
and for this you URL call should be