我正在尝试在我的项目barryvdh中使用带有Lavarel 4.2.0的dompdf包,我尝试安装此包的三个不同版本(0.6 *,0.6.1,0.5.2)
Route::get('/invoice', function()
{
$pdf = App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1>');
return $pdf->stream();
});
每次尝试使用
创建PDF文件时怎么样?Class dompdf.wrapper does not exist (vendor\laravel\framework\src\Illuminate\Container\Container.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
我收到此错误
until
答案 0 :(得分:0)
根据the docs,我们需要为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 中register the service provider and facade。
答案 1 :(得分:-1)
我将文件config/app.php
放入providers
部分:
Barryvdh\DomPDF\ServiceProvider::class,
进入aliases
部分:
'PDF' => Barryvdh\DomPDF\Facade::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.*"
}, ...