类dompdf.wrapper不存在laravel 4.2.0



我正试图在barryvdh撰写的项目中使用带有Lavarel 4.2.0的dompdf包,我尝试安装该包的三个不同版本(0.6*、0.6.1,0.5.2)

"name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.2.*",
        "fzaninotto/faker": "^1.6",
        "barryvdh/laravel-dompdf": "0.5.2"

每次我尝试使用创建PDF文件时

Route::get('/invoice', function()
{
$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->stream();
});

我收到这个错误

Class dompdf.wrapper does not exist (vendorlaravelframeworksrcIlluminateContainerContainer.php)
/ hand back the results of the functions, which allows functions to be
        // used as resolvers for more fine-tuned resolution of these objects.
        if ($concrete instanceof Closure)
        {
            return $concrete($this, $parameters);
        }
        $reflector = new ReflectionClass($concrete);
        // If the type is not instantiable, the developer is attempting to resolve

根据文档,我们需要为Laravel 4安装0.4.x版本。您的项目正在使用Laravel 5的版本。

composer.json:

"require": { 
    ... 
    "barryvdh/laravel-dompdf": "0.4.*"
}

要从容器中解析dompdf服务,请使用'dompdf',而不是'dompdf.wrapper':

$pdf = App::make('dompdf');

或者,使用PDF立面:

use PDF; 
... 
$pdf = PDF::loadHTML('<h1>Test</h1>');

请确保在config/app.php.

中注册服务提供商和facade

我将文件config/app.php放入providers部分:

BarryvdhDomPDFServiceProvider::class,

并进入aliases段:

'PDF'       => BarryvdhDomPDFFacade::class,

我在我的控制器中使用这个:

use PDF;
...
$pdf = PDF::loadView('panel.cooperation-offers.pdf', $showData);

这是我的composer.json:

...
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.2.*",
    "barryvdh/laravel-dompdf": "0.6.*"
}, ...

最新更新