【问题标题】:"Fatal error: Class not found in..", Composer package not recognized“致命错误:在..中找不到类”,无法识别 Composer 包
【发布时间】: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


    【解决方案1】:

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

    require_once('vendor/autoload.php');
    

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

    【讨论】:

      猜你喜欢
      • 2015-12-16
      • 1970-01-01
      • 2015-03-05
      • 2017-12-28
      • 2013-12-10
      • 2014-10-03
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      相关资源
      最近更新 更多