gpt4 book ai didi

php - "Fatal error: Class not found in..", Composer 包无法识别

转载 作者:行者123 更新时间:2023-12-04 21:50:38 24 4
gpt4 key购买 nike

我在 Putty 中运行了这个调用,它成功地安装了资源:

php composer.phar require --dev "mikehaertl/php-pdftk:*"

然后我向我的 composer.json 添加了一些东西:

{
"name": "you/bootstrap-canvas-wp",
"type": "wordpress-theme",
"require": {
"composer/installers": "~1.0"
},
"require-dev": {
"mikehaertl/php-pdftk": "*"
},
"extra": {
"installer-paths": {
"wp-content/themes/bootstrap-canvas-wp/": ["type:wordpress-theme"]
}
}
}

接下来我在我的作曲文件上运行了一个update命令:

php composer.phar update

我在该主题文件夹 /public_html/wp-content/themes/bootstrap-canvas-wp 中有一个文件,其中包含以下代码:

use \mikehaertl\pdftk\Pdf;

$pdf = new Pdf('mypdf.pdf');
$pdf->flatten()
->saveAs('mypdf2.pdf');

最后,我将这段代码放在主题文件夹内的 functions.php 文件中,以使这些类可用:

require_once(ABSPATH. '../vendor/autoload.php');

我的代码编辑器可以识别这些资源,但我的浏览器出现错误:

Fatal error: Class 'mikehaertl\pdftk\Pdf' not found in /home/myusername/public_html/wp-content/themes/bootstrap-canvas-wp/flattenPDF.php on line 1

关于如何实现这个功能有什么建议吗?

编辑:我也为 use 语句尝试过这种语法:(发生同样的错误)

use mikehaertl\pdftk\Pdf;

最佳答案

当没有正确调用自动加载时,我遇到了同样的错误。为我解决的是:

require_once('vendor/autoload.php');

我在纯 php 项目中使用它,我使用它的 php 页面与 mikehaertl 文件夹是同一个文件夹。所以我确定您的问题与此有关

关于php - "Fatal error: Class not found in..", Composer 包无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39533795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com