2016-08-10 1 views
0

私は初めて自分の作品にlaravelを使用しています。私はPDFを作成する必要があります。私はDompdfについて読んでいます。私はセットアップしました.HTMLコードをloadHtml();Dompdfがlaravel 5.2で自分のビューを読み込めないのはなぜですか?

未定義の変数:しかし、私はビューをロードすることはできません、これは例外で、請求書(閲覧:C:\ユーザーははEinar \ドキュメント\ \ PROYECTOS \ Ecotoner \実際の\ EcoTonerリソース\ビュー\ \ ORDENES \ invoice.blade.php)

私はこのコードを次のようだ:

use Illuminate\Http\Request; 

use App\Http\Requests; 

class PdfController extends Controller 
{ 
// 
    public function invoice() 
    { 
     $data = $this->getData(); 
     $date = date('Y-m-d'); 
     $invoice = "2222"; 
     $view = 
\View::make('ordenes.invoice',compact('data','date','invoice')); 
     $pdf = \App::make('dompdf.wrapper'); 
     $pdf->loadHTML($view); 
     return $pdf->stream('invoice'); 

     //$pdf = \PDF::loadView('ordenes.invoice', $data); 
     //return $pdf->stream(); 
    } 

    public function getData() 
    { 
    $data = [ 
     'quantity'  => '1' , 
     'description' => 'some ramdom text', 
     'price' => '500', 
     'total'  => '500' 
    ]; 
    return $data; 
    } 
} 

をし、これが私の見解です:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
<title>Example 2</title> 
<!--{!! Html::style('assets/css/pdf.css') !!}--> 
</head> 
<body> 

<main> 
    <div id="details" class="clearfix"> 
    <div id=""> 
     <h1>INVOICE</h1> 
     <div class="">Date of Invoice:</div> 
    </div> 
    </div> 
    <table border="0" cellspacing="0" cellpadding="0"> 
    <thead> 
     <tr> 
     <th class="no">#</th> 
     <th class="desc">DESCRIPTION</th> 
     <th class="unit">UNIT PRICE</th> 
     <th class="total">TOTAL</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td class="no">{{ $data['quantity'] }}</td> 
     <td class="desc">{{ $data['description'] }}</td> 
     <td class="unit">{{ $data['price'] }}</td> 
     <td class="total">{{ $data['total'] }} </td> 
     </tr> 

    </tbody> 
    <tfoot> 
     <tr> 
     <td colspan="2"></td> 
     <td >TOTAL</td> 
     <td>$6,500.00</td> 
     </tr> 
    </tfoot> 
    </table> 
</body> 
</html> 

誰かが私を助けてくれることを願っています。ドキュメントlaravel-dompdf 1として感謝

答えて

0

は、次のようにコードを変更してみてください

$pdf = \PDF::loadView('ordenes.invoice',compact('data','date','invoice')); 
return $pdf->download('invoice.pdf'); 
+0

働くようですが、私は60秒の_Maximum実行時間exceeded_私は私のphp.iniが、変更なしでmax_execution_timeはでそれを変更するがスローされます。 – Alxs

+0

ああ、ブラウザにファイルをダウンロードするように指示するレスポンスを生成する必要があります: return response() - > file($ pathToFile); または return response() - > file($ pathToFile、$ headers); – Alexanderp

+0

return response() - >ファイル($ pathToFile); または return response() - > file($ pathToFile、$ headers); – Alexanderp

関連する問題