我在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');我的代码编辑器识别这些资源,但我在浏览器中得到一个错误:
致命错误:在第1行的/home/myusername/public_html/wp-content/themes/bootstrap-canvas-wp/flattenPDF.php中找不到'mikehaertl\pdftk\Pdf‘类
对于如何使这个功能发挥作用,有什么建议吗?
编辑:我也尝试过use语句的语法:(同样的错误会发生)
use mikehaertl\pdftk\Pdf;发布于 2020-01-08 09:23:24
当autoload没有正确调用时,我也得到了相同的错误。对我来说解决的是:
require_once('vendor/autoload.php');我在简单的php项目中使用它,我使用它的php页面与mikehaertl文件夹相同。所以我相信你的问题与此有关
https://stackoverflow.com/questions/39533795
复制相似问题