DOM/PDF 错误 - 不应静态调用非静态方法 Barryvdh\DomPDF\PDF::download()
DOM/PDF error - Non-static method Barryvdh\DomPDF\PDF::download() should not be called statically
我的控制器是这样的:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Barryvdh\DomPDF\Facade as PDF;
class PrintPDF extends Controller
{
public function print(){
$details =['title' => 'test'];
$pdf = PDF::loadView('textDoc', $details);
return $pdf::download('this.pdf');
}
}
我的路线
Route::get('/print', 'PrintPDF@print');
访问 localhost/print 时出现错误
Non-static method Barryvdh\DomPDF\PDF::download() should not be called
statically
我按照他们网站上的安装说明进行了操作。我试图改变我的控制器添加使用 PDF,而不是使用 Barryvdh\DomPDF\Facade 作为 PDF;但错误仍然存在
像这样调用函数
return $pdf->download('invoice.pdf');
发生这种情况是因为您为错误的 PDF 命名空间 class。
您正在命名空间 Barryvdh\DomPDF\PDF 并尝试将此 class 用作“Facade”,这是错误的。
解决你的问题
将命名空间设置为门面:
use Barryvdh\DomPDF\Facade as PDF;
函数应该是这样的
$details =['title' => 'test'];
$pdf = PDF::loadView('Your view path', $details);
可以直接使用下载方式下载
return $pdf->dowload('test.pdf');
或者您可以保存在项目的特定目录中
return $pdf->save('path of your directory/filename.pdf');
这对我有用....
我的控制器是这样的:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Barryvdh\DomPDF\Facade as PDF;
class PrintPDF extends Controller
{
public function print(){
$details =['title' => 'test'];
$pdf = PDF::loadView('textDoc', $details);
return $pdf::download('this.pdf');
}
}
我的路线
Route::get('/print', 'PrintPDF@print');
访问 localhost/print 时出现错误
Non-static method Barryvdh\DomPDF\PDF::download() should not be called statically
我按照他们网站上的安装说明进行了操作。我试图改变我的控制器添加使用 PDF,而不是使用 Barryvdh\DomPDF\Facade 作为 PDF;但错误仍然存在
像这样调用函数
return $pdf->download('invoice.pdf');
发生这种情况是因为您为错误的 PDF 命名空间 class。 您正在命名空间 Barryvdh\DomPDF\PDF 并尝试将此 class 用作“Facade”,这是错误的。
解决你的问题 将命名空间设置为门面:
use Barryvdh\DomPDF\Facade as PDF;
函数应该是这样的
$details =['title' => 'test'];
$pdf = PDF::loadView('Your view path', $details);
可以直接使用下载方式下载
return $pdf->dowload('test.pdf');
或者您可以保存在项目的特定目录中
return $pdf->save('path of your directory/filename.pdf');
这对我有用....