php - شرح - نموذجا ام انموذجا
Yii2: كيفية إضافة نموذج ونموذج معرف في مبدف (2)
أنا بحاجة إلى إنشاء قوات الدفاع الشعبي من وجهة نظري، إم باستخدام مبتك كارتيك،
مراقب :
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();
}
الحصول على خطأ Undefined variable: model
. حاولت كما هو مبين أعلاه ولكن الحصول على نفس الخطأ.
رأي:
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,
]);
}
حل العمل الكامل
public function actionInvoicesPrint($id)
{
$model = $this->findModel($id);
$searchModel = new InvoicesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$data = Invoices::findOne($id);
$content = $this->renderPartial('view', ['model' => $model,'dataProvider' => $dataProvider,'searchModel' => $searchModel,'data'=> $data]);
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_BLANK,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content,
]);
return $pdf->render();
}
في عرض لتحريك actionInvoicesPrint()
تحكم actionInvoicesPrint()
<?php
echo Html::a('<i class="fa glyphicon glyphicon-hand-up"></i> Privacy Statement', ['/invoices/invoices-print', 'id' => $model->id], [
'class'=>'btn btn-danger',
'target'=>'_blank',
'data-toggle'=>'tooltip',
'title'=>'Will open the generated PDF file in a new window'
]);
?>
في أكتيونينفوسبرينت لديك لم يتم تعيين نموذج $
أدناه عينة من بلدي بدف العمل (مبتك كارتيك مثل الخاص بك)
$model = $this->findModel($id);
// get your HTML raw content without any layouts or scripts
//$this->layout = 'pdfmain';
$content = $this->renderPartial('_mpdf_report_scheda', [
'model' => $model,
'imglink' => $imglink,
]);
if ($print ) {
$setJS = 'this.print();';
}
else {
$setJS ='';
}
// setup kartik\mpdf\Pdf component
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_BLANK,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_PORTRAIT,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content,
كما ترون في هذا الجزء من التعليمات البرمجية يتم الحصول على نموذج .the قبل كل شيء وبعد ذلك مع هذا النموذج $ يعرف ريندبارتيال مع وجهة النظر المناسبة ..
لتمرير معرف $ يجب أن يكون العمل
public function actionInvoicesPrint($id)
ولهذا يجب أن تكون دعوة ورل
Url::to(['/your-controller/Invoices-print' , 'id' => $your_id]);