2016-07-22 72 views
0

我想在我的barryvdh創作的項目中使用Lavarel 4.2.0的dompdf包,我試着安裝這個包的三個不同版本(0.6 *,0.6.1 ,0.5.2)類dompdf.wrapper不存在laravel 4.2.0

"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" 

如何以往每次我試圖創建一個使用

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 

回答

-1

我把文件config/app.phpproviders部分:

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.*" 
}, ... 
0

the docs,我們需要安裝0.4.x版本Laravel 4.你的項目使用版本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>'); 

一定要register the service provider and facade配置/ app.php