“致命错误:找不到类.",无法识别Composer程序包

编程入门 行业动态 更新时间:2024-10-26 00:29:44
本文介绍了“致命错误:找不到类.",无法识别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程序包

本文发布于:2023-07-15 10:31:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110677.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   错误   无法识别   程序包   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!