laravel 未找到“Dompdf\Dompdf”类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36354214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:30:54  来源:igfitidea点击:

Class 'Dompdf\Dompdf' not found

phplaraveldompdf

提问by RHM

I'm trying to install dompdf using composer, I followed the instructions from Installing DOMPDF with Composer

我正在尝试使用Composer 安装 dompdf,我按照使用 Composer 安装 DOMPDF 中的说明进行操作

So far I've

到目前为止我已经

  • In composer.json

    ...
    "require": {
        ...
        "dompdf/dompdf": "~0.6.1"
    },
    "autoload": {
    ....
    
  • run composer update

  • in autoload.php already have require __DIR__.'/../vendor/autoload.php';
  • In vendor/dompdf/dompdf/dompdf_config.inc.php changed def("DOMPDF_ENABLE_AUTOLOAD", true);to def("DOMPDF_ENABLE_AUTOLOAD", false);
  • My controller code
  • 在 composer.json 中

    ...
    "require": {
        ...
        "dompdf/dompdf": "~0.6.1"
    },
    "autoload": {
    ....
    
  • composer update

  • 在 autoload.php 中已经有 require __DIR__.'/../vendor/autoload.php';
  • 在供应商/ DOMPDF / DOMPDF / dompdf_config.inc.php改变def("DOMPDF_ENABLE_AUTOLOAD", true);def("DOMPDF_ENABLE_AUTOLOAD", false);
  • 我的控制器代码

```

``

use Dompdf\Adapter\CPDF;      
use Dompdf\Dompdf;
use Dompdf\Exception;

require_once "vendor/dompdf/dompdf/dompdf_config.inc.php";

class ArticleController extends BaseController {
  ...
  public function downloadPdf(){
    $dompdf = new Dompdf();
    $dompdf->loadHtml('hello world');
    $dompdf->render();
    $dompdf->output();
  }
}
  • "post" route for ArticleController@downloadPdf
  • ArticleController@downloadPdf 的“发布”路由

so now when I try to download pdf, if gives me error:

所以现在当我尝试下载 pdf 时,如果给我错误:

exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'Dompdf\Dompdf' not found'

异常 'Symfony\Component\Debug\Exception\FatalErrorException' 带有消息 'Class 'Dompdf\Dompdf' not found'

have I missed any setup step or doing something wrong?

我是否错过了任何设置步骤或做错了什么?

采纳答案by RHM

This issue at dompdf github pagehelped me to solve this error

dompdf github页面上的这个问题帮助我解决了这个错误

The latest stable (0.6.1) does not support namespaces and so would not need the use statement in your code. The upcoming release (0.7.0) does include namespace support.

最新的稳定版 (0.6.1) 不支持命名空间,因此在您的代码中不需要 use 语句。即将发布的版本 (0.7.0) 确实包含命名空间支持。

So, I just removed

所以,我刚刚删除

use Dompdf\Adapter\CPDF;      
use Dompdf\Dompdf;
use Dompdf\Exception;

and used new DOMPDF();instead of new Dompdf();as with version 0.6.* namespace will not work.

并用0.6.* 命名空间new DOMPDF();代替new Dompdf();0.6.* 命名空间将不起作用。

回答by Federkun

I don't think that you want use the dompdf 0.6 family. In the 0.6 version all the classes are in global space. But since your code is ready to the 0.7, change it to

我不认为你想使用dompdf 0.6 family。在 0.6 版本中,所有类都在全局空间中。但是由于您的代码已准备好使用 0.7,请将其更改为

"dompdf/dompdf": "~0.7"

and run composer update.

并运行composer update

回答by Bayu Setiawan

Open file config.php

打开文件 config.php

application/config/config.php

Then Change

然后改变

$config['composer_autoload'] = "FALSE";

To

$config['composer_autoload'] = "vendor/autoload.php";