title: How to print/display current search criteria into PDF using Yii2 and mpdf?
body: <p>I've been trying to implement MPDF over the search function from Yii2 advanced template but doesn't seem to give the result I've wanted.</p>
  
  <p>What I want is when I put the value inside the <code>textField(sales_id)</code>, I should be able to operate Print Button using MPDF extension where the condition is that the data showed in mpdf should only contains similar sales_id value in it's fields, like this image below:</p>
  
  <p><a href="https://i.stack.imgur.com/vhYJz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vhYJz.png" alt="view example"></a></p>
  
  <p>I made the method in my controller like so:</p>
  
  <pre><code>public function actionPrintPerSales()
      {
          // trying to get the sales_id post value
          $request = Yii::$app-&gt;request;
          $sales_id = $request-&gt;post('sales_id');
          $model = new PiutangCustomer();
  
  
  
      // Your SQL query filter here
      $dataProvider = new ActiveDataProvider([
          'query' =&gt; PiutangCustomer::find()
              -&gt;where(['status_piutang' =&gt; '0'])
              -&gt;andWhere(['sales_id'] =&gt; $sales_id)
              -&gt;orderBy(['customer_id' =&gt; SORT_ASC])
      ]);
  
      $content = $this-&gt;renderPartial('_print-per-sales', ['model', 'dataProvider' =&gt; $dataProvider]);
  
      // setup kartik\mpdf\Pdf component
      $pdf = new Pdf([
      // set to use core fonts only
      'mode' =&gt; Pdf::MODE_CORE,
      // A4 paper format
      'format' =&gt; Pdf::FORMAT_A4,
      // portrait orientation
      'orientation' =&gt; Pdf::ORIENT_PORTRAIT,
      // stream to browser inline
      'destination' =&gt; Pdf::DEST_BROWSER,
      // your html content input
      'content' =&gt; $content,
      // format content from your own css file if needed or use the
      // enhanced bootstrap css built by Krajee for mPDF formatting
      'cssFile' =&gt; '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
      // any css to be embedded if required
      'cssInline' =&gt; '.kv-heading-1{font-size:18px}',
      // set mPDF properties on the fly
      'options' =&gt; ['title' =&gt; 'Cetak Laporan Piutang Menurut Customer'],
      // call mPDF methods on the fly
      'methods' =&gt; [
      'SetHeader'=&gt;['Laporan Piutang - NAMA TOKO / PERUSAHAAN / CV'],
      'SetFooter'=&gt;['Powered by PFSOFT | {PAGENO}'],
      ]
      ]);
  
      /*------------------------------------*/
      Yii::$app-&gt;response-&gt;format = \yii\web\Response::FORMAT_RAW;
      $headers = Yii::$app-&gt;response-&gt;headers;
      $headers-&gt;add('Content-Type', 'application/pdf');
      /*------------------------------------*/
  
      // return the pdf output as per the destination setting
      return $pdf-&gt;render();
      }
  </code></pre>
  
  <p>For the View I made something like this:</p>
  
  <pre><code>&lt;?php echo $this-&gt;render('_search-per-sales', ['model' =&gt; $searchModel]); ?&gt;
  </code></pre>
  
  <p>And the sub-form _search-per-sales View:</p>
  
  <pre><code>&lt;?php $form = ActiveForm::begin([
          'action' =&gt; ['print-per-sales'],
          'method' =&gt; 'post',
      ]); ?&gt;
  
  &lt;?= $form-&gt;field($model, 'sales_id')-&gt;textInput() ?&gt;
  
  &lt;div class="form-group"&gt;
      &lt;?= Html::submitButton(Yii::t('app', 'PRINT'), ['class' =&gt; 'fa fa-print btn btn-warning']) ?&gt;
  &lt;/div&gt;
  
  &lt;?php ActiveForm::end(); ?&gt;
  </code></pre>
  
  <p>And as for the rendered view from the actionPrintPerSales  (_print-per-sales) :</p>
  
  <pre><code>&lt;?= GridView::widget([
          'dataProvider' =&gt; $dataProvider,
          //'filterModel' =&gt; $searchModel,
          'columns' =&gt; [
              ['class' =&gt; 'yii\grid\SerialColumn'],
              // 'customer_id',
              [
                  'label' =&gt; 'Nama Customer',
                  'value' =&gt; 'customer.first_name',
              ],
              [
                  'attribute' =&gt; 'nilai_piutang',
                  'contentOptions' =&gt; ['style' =&gt; 'text-align:right'],
                  'format'=&gt;['decimal',0],
              ],
              [
                  'attribute' =&gt; 'total_bayar',
                  'contentOptions' =&gt; ['style' =&gt; 'text-align:right'],
                  'format'=&gt;['decimal',0]
              ],
              [
                  'attribute' =&gt; 'sisa_piutang',
                  'contentOptions' =&gt; ['style' =&gt; 'text-align:right'],
                  'format'=&gt;['decimal',0]
              ],
              'faktur',
              [
                  'attribute' =&gt; 'tanggal_jatuh_tempo',
                  'contentOptions' =&gt; ['style' =&gt; 'text-align:center'],
                  'format' =&gt; ['date', 'php:d-M-Y']
              ],
              'sales_id',
              [
                  'label' =&gt; 'Nama Sales',
                  'value' =&gt; function ($data){ return $data-&gt;kodeSales-&gt;nama; },
              ],  
          ],
      ]); ?&gt;
  </code></pre>
  
  <p>There's something wrong with my SQL query filter, inside controller. I can tell my mpdf is working because when I comment out the where clause:</p>
  
  <pre><code>// -&gt;andWhere('sales_id' = $sales_id)
  </code></pre>
  
  <p>The pdf is working, only it shows all the data without filtering sales_id.</p>