PHP 致命错误 – yii\base\ErrorException Class 'Dompdf\FrameDecorator\Page' 未找到

PHP Fatal Error – yii\base\ErrorException Class 'Dompdf\FrameDecorator\Page' not found

我正在尝试在我的 yii2 应用程序中使用 Dompdf,但它向我显示一条错误消息。

PHP Fatal Error – yii\base\ErrorException Class
'Dompdf\FrameDecorator\Page' not found

我不明白这是为什么。

您应该 运行 此命令将此扩展程序添加到您的 composer.json。

composer require dompdf/dompdf

或将此行添加到您的 composer.json 要求部分和 运行 composer update:

"require": {
    "dompdf/dompdf": "^0.7.0"
},

然后在你的视图中这样访问。

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream();