How to passing from activeform in yii2 to pdf

I’ve created form and invoice using mpdf kartik. I want when user inserted to form and stored to database, the data value from form it’s will be passing value to invoice mpdf kartik. But I don’t know way for passing value to pdf, please advice me.

In controller :


<?php


namespace app\controllers;


use Yii;

use app\models\TandaTerima;

use yii\web\Controller;

use yii\web\NotFoundHttpException;

use yii\filters\VerbFilter;

use yii\filters\AccessControl;

use app\models\Donatur;

use app\models\Pengurus;

use app\models\User;

use yii\helpers\Json;

use kartik\mpdf\Pdf;


class TandaTerimaController extends Controller

{

	public function behaviors()

	{

		return [

            'access' => [

                'class' => AccessControl::className(),

                'only' => ['create'],

                'rules' => [

                    [

                        'actions' => ['create'],

                        'allow' => true,

                        'roles' => ['@'],

                    ],

                ],

            ],

            'verbs' => [

                'class' => VerbFilter::className(),

                'actions' => [

                    'delete' => ['POST'],

                ],

            ],

		];

	}


    public function actionReport() 

    {

        $tandaTerima = new TandaTerima();

        if (!$tandaTerima) {

            throw new NotFoundHttpException("The tanda terima was not found.");

        }


        $tandaTerima->tgl_terima = date('Y-m-d');


        $donatur = new Donatur();

        if (!$donatur) {

            throw new NotFoundHttpException("The donatur has tanda terima.");

        }


        $user = new User();

        if (!$user) {

            throw new NotFoundHttpException("The donatur has tanda terima.");

        }


        // Your SQL query here

        $content = $this->renderPartial('coba', [

            'tandaTerima' => $tandaTerima,

            'donatur' => $donatur,

        ]);


        // setup kartik\mpdf\Pdf component

        $pdf = new Pdf([

        // set to use core fonts only

        'mode' => Pdf::MODE_CORE,

        // 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,

        // format content from your own css file if needed or use the

        // enhanced bootstrap css built by Krajee for mPDF formatting

        'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',

        // any css to be embedded if required

        'cssInline' => '.kv-heading-1{font-size:18px}',

        // set mPDF properties on the fly

        'options' => ['title' => 'Surat Tanda Terima'],

        // call mPDF methods on the fly

        'methods' => [

        //  'SetHeader'=>['Surat Tanda Terima'],

            'SetFooter'=>['{PAGENO}'],

            ]

        ]);


        /*------------------------------------*/

        Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;

        $headers = Yii::$app->response->headers;

        $headers->add('Content-Type', 'application/pdf');

        /*------------------------------------*/


        // return the pdf output as per the destination setting

        return $pdf->render('coba', [

            'tandaTerima' => $tandaTerima,

            'donatur' => $donatur,

        ]);

    }


	public function actionIndex()

	{

		return $this->redirect(['create']);

	}




    public function actionGetDonatur($kodeId)

    {

        $donatur = Donatur::findOne($kodeId);

        echo Json::encode($donatur);

    }


	public function actionCreate()

	{

        $tandaTerima = new TandaTerima();

        if (!$tandaTerima) {

            throw new NotFoundHttpException("The tanda terima was not found.");

        }


        $donatur = new Donatur();

        if (!$donatur) {

            throw new NotFoundHttpException("The donatur has tanda terima.");

        }


        $user = new User();

        if (!$user) {

            throw new NotFoundHttpException("The donatur has tanda terima.");

        }

        

        // Display datetime in form and save to table

        $tandaTerima->tgl_terima = date('Y-m-d');


        // Dispaly kode pengurus in form and save to table

        $tandaTerima->kode_pengurus = \Yii::$app->user->identity->id; 


        if ($tandaTerima->load(Yii::$app->request->post()) && $tandaTerima->save()) {

                Yii::$app->session->setFlash('success', 'Data berhasil disimpan!');

                return $this->redirect(['report']);

                return $this->refresh();

        } 

        

        return $this->render('create', [

            'tandaTerima' => $tandaTerima,

            'donatur' => $donatur,

        ]);

        

	}

}



In view pdf :


<?php


use yii\helpers\Html;

use yii\bootstrap\ActiveForm;

use yii\widgets\Pjax;


/* @var $this yii\web\View */

/* @var $model app\models\Donatur */

?>

<?php $form = ActiveForm::begin(['layout' => 'horizontal', 'enableAjaxValidation' => false,

    'id' => 'update-form',


    ]); ?>

<html>

<head>

<style type="text/css">

<!--

#apDiv1 {

	position:absolute;

	left:136px;

	top:16px;

	width:431px;

	height:116px;

	z-index:1;

}

#apDiv2 {

	position:absolute;

	left:635px;

	top:180px;

	width:63px;

	height:32px;

	z-index:2;

}

.style3 {

    font-size: 20px;

    font-weight: bold;

}

.style9 {font-size: 15px}

.style10 {font-size: 15px}

#apDiv3 {

	position:absolute;

	left:607px;

	top:205px;

	width:86px;

	height:35px;

	z-index:2;

}

#apDiv4 {

	position:absolute;

	left:78px;

	top:163px;

	width:534px;

	height:111px;

	z-index:3;

}

#apDiv5 {

	position:absolute;

	left:527px;

	top:204px;

	width:73px;

	height:57px;

	z-index:4;

}

-->

</style>

</head>

<body style="color:#000066;">

<div id="apDiv1">

<p align="center"><span class="style9">PANTI ASUHAN DAN SANTUNAN KELUARGA </span><BR>

  <span class="style3">MUHAMMADIYAH DAN AISYIYAH </span><BR>

  <span class="style10">CABANG RAWAMANGUN PULOGADUNG</span><br>

  <span>Jalan Rukem II/3 Rawamangun Jakarta 13220 Telepon 471 829<br>

  BRI KCP Sunan Giri Rek. Britama No.0530.01.002755.50.9

  <span style="text-decoration: underline;"></span></p>

</div>

<br>

<hr style="color:#000066;">

<p align="center"><strong>TANDA&nbsp;TERIMA</strong></p>


<p><strong><em>&nbsp;</em></strong></p>

<table style="height: 116px;" width="271">

<tbody>

<tr>

<td>Sudah&nbsp;Terima&nbsp;dari :</td>

<td></td>

</tr>

<tr>

<td>Alamat :</td>

<td></td>

</tr>

<tr>

<td>Banyaknya&nbsp;Uang&nbsp; :</td>

<td></td>

</tr>

<tr>

<td>&nbsp;</td>

<td></td>

</tr>

<tr>

<td>Untuk&nbsp;Pembayaran :</td>

<td></td>

</tr>

<tr>

<td>&nbsp;</td>

<td></td>

</tr>

</tbody>

</table>

<p>Selanjutnya akan kami salurkan kepada mereka yang berhak menerimanya.</p>

<p>Dengan nama Allah yang Maha pengasih lagi maha penyayang semoga Allah SWT. Memberi pahala kepada anda, atas barang yang anda berikan dan mudah-mudahan Allah SWT. Memberi berkat kepada anda atas apa saja yang masih tinggal. Muda-mudahan dijadikanNya kesucian bagi anda.</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<table>

<tbody>

<tr>

<td width="197"><p></p>

<p>Yang&nbsp;Menyerahkan,</p>

</td>

<td width="197">

<p>&nbsp;</p>

</td>

<td width="197">

	<p style="text-align: right;">Jakarta, <?php 

		$my_model->no_tanda_terima;

	?></p>

<p>Yang&nbsp;menerima,</p>

</td>

</tr>

<tr>

<td width="197">

	<br><br><br>

	</td>

<td width="197">&nbsp;</td>

<td width="197">

	<br><br><br>

	</td>

</tr>

</tbody>

</table>

<p>&nbsp;</p>

<p>&nbsp;</p>

</body>

</html>

<?php ActiveForm::end();?>

This invoice using mpdf…

7211

Invoice.JPG

It looks like you are starting with actionCreate() and then redirecting to actionReport(). When you create the report, and save the data, you should pass the id of this newly created model to the report action ($id). You want to call findModel($id) like





public function actionReport($id)

{

  //since you use $my_model->attribute on the view

  $my_model = $this->findModel($id);

   $content = $this->renderPartial('coba',['my_model'=>$my_model]);