【发布时间】:2017-01-24 19:39:22
【问题描述】:
我在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');
我的代码编辑器可以识别这些资源,但我的浏览器出现错误:
致命错误:类 'mikehaertl\pdftk\Pdf' 未在 /home/myusername/public_html/wp-content/themes/bootstrap-canvas-wp/flattenPDF.php 第 1 行
关于如何使它起作用的任何建议?
编辑:我也为use 语句尝试了这种语法:(同样的错误发生)
use mikehaertl\pdftk\Pdf;
【问题讨论】:
标签: php wordpress class composer-php