Yii2 ~ 错误请求 (#400) 缺少必需的参数:创建 pdf 时的 id

Yii2 ~ Bad Request (#400) Missing required parameters: id while creating pdf

我正在尝试使用 Yii2 mPDF 扩展创建发票的 PDF,我可以很好地创建 pdf,但我想将视图数据传递到 Pdf 中,但这似乎不起作用。

控制器:

public function actionMpdfDemo1($id) {
  $model = Facturen::findOne($id);
    $content = $this->renderPartial('factuur', [
        'model' => $model,
        'company' => $company,
    ]);
    $pdf = new Pdf([
        'mode' => Pdf::MODE_UTF8, // leaner size using standard fonts
        'format' => Pdf::FORMAT_A4,
        'orientation' => Pdf::ORIENT_PORTRAIT,
        'content' => $content,
        'options' => [
            'title' => 'Factuur',
            'subject' => 'Generating PDF files via yii2-mpdf extension has never been easy'
        ],
        'methods' => [
            'SetHeader' => ['Generated By: Krajee Pdf Component||Generated On: ' .  date("l j F Y")],
            'SetFooter' => ['|Page {PAGENO}|'],
        ]
    ]);
    return $pdf->render();
}

观点:

<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use app\models\Facturen;
use helpers\ArrayHelper;
use app\models\Producten;
/* @var $this yii\web\View */
/* @var $model app\models\Facturen */
/* @var $modelProducten app\models\Producten */

$this->title = 'Factuur: '. $model->factuur_id;
$this->params['breadcrumbs'][] = ['label' => 'Factures', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="facturen-view">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('Update', ['update', 'id' => $model->factuur_id], ['class' => 'btn btn-primary']) ?>
        <?= Html::a('Delete', ['delete', 'id' => $model->factuur_id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
        ]) ?>
    </p>

    <?= DetailView::widget([
        'model' => $model,
        'modelProducten' => $modelProducten,
        'attributes' => [
            'factuur_id',
            'company.company_name',
            'person.Contactpersoon',
//            'person.last_name',
            'product.product_id',
            'product.product_name',
            'product.amount',
            'product.price',
            'date',
        ],
    ]) ?>
<p>
<?php        echo Html::a('<i class="fa glyphicon glyphicon-hand-up"></i> Factuur genereren', ['/facturen/mpdf-demo-1'], [
        'class'=>'btn btn-danger',
        'target'=>'_blank',
        'data-toggle'=>'tooltip',
        'title'=>'Will open the generated PDF file in a new window'
        ]); ?>
    </p>
<?php var_dump($model)?>
</div>

以及我创建 "factuur"

的页面
<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use app\models\Facturen;
use helpers\ArrayHelper;
use app\models\Producten;
/* @var $this yii\web\View */
/* @var $model app\models\Facturen */
/* @var $modelProducten app\models\Producten */
$this->title = 'Factuur: '?>
<div class="container">
    <div class="row">
        <div class="col-xs-12">
            <div class="invoice-title">
                <h3 class="pull-right" style="float: right;">Factuurnummer # <?php echo $model->factuur_id; ?></h3>
            </div>
            <hr>
            <div class="row">
                <div class="col-xs-6">
                    <address>
                        <strong>Bedrijsnaam: </strong><?php echo $model->company->company_name; ?><br>
                        <strong>Contactpersoon: </strong><?php echo $model->person->Contactpersoon;?><br>
                    </address>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <address>
                        <strong>Betaal Methode:</strong><br>
                        Visa ending **** 4242<br>
                        jsmith@email.com
                    </address>
                </div>
                <div style="float: right;" class="col-xs-6 text-right">
                    <address>
                        <strong>Factuurdatum:</strong><br>
                        <?php echo $model->date; ?><br><br>
                    </address>
                </div>
            </div>
       <.....>

这是视图,您会看到一个 var 转储。有些未设置字段也是一个问题,但我已经提出了一个问题:

这有点像我想要的,但内容取决于 ID:

操作参数中缺少 $id

Html::a('<i class="fa glyphicon glyphicon-hand-up"></i> Factuur genereren', 
    ['/facturen/mpdf-demo-1', 'id' => $model->factuur_id],
    [
       'class'=>'btn btn-danger',
       'target'=>'_blank',
       'data-toggle'=>'tooltip',
       'title'=>'Will open the generated PDF file in a new window'
    ]
);