简体   繁体   English

Drupal 7网站中dompdf的致命PHP错误

[英]Fatal PHP error with dompdf in drupal 7 site

I am trying to add some dompdf functionality to a Drupal 7 website. 我正在尝试向Drupal 7网站添加一些dompdf功能。 I using a composer autoload to load dompdf. 我使用作曲家自动加载来加载dompdf。 In an XAMPP installation on a windows PC dompdf works fine and produces nice pdf files. 在Windows PC上的XAMPP安装中,dompdf可以正常工作,并且可以生成漂亮的pdf文件。

I have copied the document root to an EC2 instance on AWS that is running RHEL Linux. 我已将文档根目录复制到运行RHEL Linux的AWS上的EC2实例。 Now I am getting a fatal PHP error. 现在,我收到了致命的PHP错误。 I thought it may because the autoload was not working for some reason so I have altered the index.php as follows 我认为可能是因为自动加载由于某种原因而无法正常工作,所以我按如下方式更改了index.php

define('DRUPAL_ROOT', getcwd());

if(file_exists(DRUPAL_ROOT . '/vendor/autoload.php')) {
  include DRUPAL_ROOT . '/vendor/autoload.php';
}

This made no difference although I checked the DRUPAL_ROOT was OK and it is /var/www/html which is correct. 尽管我检查了DRUPAL_ROOT没问题,并且它是/ var / www / html正确,但这没有什么区别。

I have tried putting 我试过了

$pdf = new Dompdf(); $ pdf =新的Dompdf();

After the include just to see if we can get past the error stage and I am still getting the fatal error as follows 包含之后,只是看我们是否可以通过错误阶段,而我仍然遇到致命错误,如下所示

PHP Fatal error: Class 'Dompdf' not found in /var/www/html/index.php on line 20 PHP致命错误:在第20行的/var/www/html/index.php中找不到类'Dompdf'

It seems to me that the autoload is not working in this environment but I have no clue why. 在我看来,自动加载无法在这种环境下工作,但我不知道为什么。

I am running RHEL on Amazon EC2 with PHP 5.4.16 and I am running Drupal 7 我正在使用PHP 5.4.16在Amazon EC2上运行RHEL并且正在运行Drupal 7

Does anyone else have experience with this sort of issue? 其他人是否有处理此类问题的经验?

Regards 问候

Richard 理查德

This should work if you specified 0.6 as the target version in composer.json, eg: 如果您在composer.json中将0.6指定为目标版本,这应该可以工作,例如:

{
  "require" : {
    "dompdf/dompdf" : "0.6.*"
  }
}

If you're using 0.7, currently in beta: 如果您使用的是0.7(当前处于测试版):

{
  "require" : {
    "dompdf/dompdf" : "0.7.*@beta"
  }
}

then you'll first need to reference the namespace before you instantiate the class: 那么在实例化类之前,首先需要引用名称空间:

use Dompdf\Dompdf;

Dompdf 0.7 will not work if you are using PHP version 5.4. 如果您使用的是PHP 5.4版,则Dompdf 0.7将无法正常工作。 I don't believe 'USE' was available before PHP version 5.6. 我不认为PHP 5.6之前的“ USE”可用。 I am still trying to get Dompdf to work with PHP version 5.4 as my hosting site only supports PHP 5.3 and 5.4. 我仍在尝试使Dompdf与PHP 5.4一起使用,因为我的托管站点仅支持PHP 5.3和5.4。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM