yii2基本打印pdf页面

时间:2015-05-25 08:35:24

标签: yii2

请帮忙。 你好,我即将完成使用yii2 basic创建的项目。我的问题是,我想打印一个使用pdf作为其输出。我试过yii2 mpdf和yii2-pdf但没有成功。我想将打印按钮放在视图文件的index.php中。这是我在索引视图文件中的代码片段。

<?= Html::a('<i class="fa glyphicon glyphicon-hand-up"></i>Property report',['/propertydetails/report'],
        [
         'class'=>'btn btn-danger',
         'target'=> '_blank',
         'data-toggle'=>'tooltip',
         'title'=>'Generate the pdf']); ?> 

这是我的控制器

use kartik\mpdf\Pdf;

//function for reports
public function actionReport()
{
    //get your html raw content without layouts
   // $content = $this->renderPartial('view');
    //set up the kartik\mpdf\Pdf component
    $pdf = new Pdf([
        'content'=>$this->renderPartial('view'),
        'mode'=> Pdf::MODE_CORE,
        'format'=> Pdf::FORMAT_A4,
        'orientation'=>Pdf::ORIENT_POTRAIT,
        'destination'=> Pdf::DEST_BROWSER,
        'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
        'cssInline'=> '.kv-heading-1{font-size:18px}',
        'options'=> ['title'=> 'Paki Properties Reports'],
        'methods'=> [
               'setHeader'=>['Generated on: '.date("r")],
               'setFooter'=>['|page {PAGENO}|'],
                ]
        ]);
    return $pdf->render();
}

当我点击按钮时出现此错误

 PHP Notice – yii\base\ErrorException

未定义的变量:模型

1. in C:\wamp\www\pakiSystems1\views\propertydetails\view.php at line 9
123456789101112131415161718

<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model app\models\Propertydetails */

$this->title = $model->propertyId;
$this->params['breadcrumbs'][] = ['label' => 'Propertydetails', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="propertydetails-view">

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

    <p>
        <?= Html::a('Update', ['update', 'id' => $model->propertyId], ['class' => 'btn btn-primary']) ?>

2. in C:\wamp\www\pakiSystems1\vendor\yiisoft\yii2\base\View.php – yii\base\View::renderPhpFile() at line 247
3. in C:\wamp\www\pakiSystems1\vendor\yiisoft\yii2\base\View.php – yii\base\View::renderFile() at line 149
4. in C:\wamp\www\pakiSystems1\vendor\yiisoft\yii2\base\Controller.php – yii\base\View::render() at line 398
5. in C:\wamp\www\pakiSystems1\controllers\PropertydetailsController.php – yii\base\Controller::renderPartial() at line 77
71727374757677787980818283

    public function actionReport()
    {
        //get your html raw content without layouts
       // $content = $this->renderPartial('view');
        //set up the kartik\mpdf\Pdf component
        $pdf = new Pdf([
            'content'=>$this->renderPartial('view'),
            'mode'=> Pdf::MODE_CORE,
            'format'=> Pdf::FORMAT_A4,
            'orientation'=>Pdf::ORIENT_POTRAIT,
            'destination'=> Pdf::DEST_BROWSER,
            'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
            'cssInline'=> '.kv-heading-1{font-size:18px}',

我将非常感谢任何帮助。提前致谢

1 个答案:

答案 0 :(得分:2)

在您的控制器中没有型号。 您必须添加此信息,例如:

$content = $this->renderPartial('_mpdf_report_scheda',  [
     'model' => $model,

     'mode'=> Pdf::MODE_CORE,
     'format'=> Pdf::FORMAT_A4,
     'orientation'=>Pdf::ORIENT_POTRAIT,
     'destination'=> Pdf::DEST_BROWSER,
     .....
           ]);