“致命错误:找不到类.",无法识别Composer程序包 [英] "Fatal error: Class not found in..", Composer package not recognized

查看:441
本文介绍了“致命错误:找不到类.",无法识别Composer程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I ran this call in Putty, it successfully installed the resource:

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

然后我在composer.json中添加了几件事:

I then added a couple of thing to my 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命令:

Next I ran an update command on my composer file:

php composer.phar update

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

I have a file located inside that theme folder /public_html/wp-content/themes/bootstrap-canvas-wp that has this code:

use \mikehaertl\pdftk\Pdf;

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

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

Finally, I placed this piece of code in my functions.php file inside the theme folder in an effort to make these classes usable:

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

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

My code editor recognizes these resources but I get an error in my browser:

致命错误:找不到类'mikehaertl \ pdftk \ Pdf' /home/myusername/public_html/wp-content/themes/bootstrap-canvas-wp/flattenPDF.php 在第1行

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

关于如何实现此功能的任何建议?

Any suggestions on how to make this functional?

编辑:我还尝试了use语句的这种语法:(发生相同的错误)

EDIT: I've also tried this syntax for the use statement: (same error happens)

use mikehaertl\pdftk\Pdf;

推荐答案

自动加载未正确调用时,我遇到了相同的错误. 为我解决的是:

I got the same error when autoload was not called correctly. What solved for me is:

require_once('vendor/autoload.php');

我在普通的php项目中使用此文件,我在其中使用它的php页面与mikehaertl文件夹位于同一文件夹.因此,我确定您的问题与此有关

I use this in plain php project,the php page where i use it it is the same folder as the mikehaertl folder. So i am sure that your issue is related to this

这篇关于“致命错误:找不到类.",无法识别Composer程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆