我试图在Codeigniter中使用PdfParser库( PDFparser链路 ),所以首先我已经下载、解压缩并安装了第三方/供应商文件夹下的库,另外,我已经下载、解压缩并安装在同一个第三方/供应商文件夹中的tcpdf库。因为我不能在远程服务器上运行Composer,所以我已经在thir/ autoload.php文件夹中创建了一个文件。文件夹结构现在如下:
third_party
vendor
autoload.php
tecnickcom
tcpdf
smalot
pdfparser
src
Smalot
PdfParser加载所有依赖项的自动加载文件的代码如下所示:
$vendorDir = '../vendor';
$tcpdf_files = Array(
'Datamatrix' => $vendorDir . '/tecnickcom/tcpdf/include/barcodes/datamatrix.php',
'PDF417' => $vendorDir . '/tecnickcom/tcpdf/include/barcodes/pdf417.php',
'QRcode' => $vendorDir . '/tecnickcom/tcpdf/include/barcodes/qrcode.php',
'TCPDF' => $vendorDir . '/tecnickcom/tcpdf/tcpdf.php',
'TCPDF2DBarcode' => $vendorDir . '/tecnickcom/tcpdf/tcpdf_barcodes_2d.php',
'TCPDFBarcode' => $vendorDir . '/tecnickcom/tcpdf/tcpdf_barcodes_1d.php',
'TCPDF_COLORS' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_colors.php',
'TCPDF_FILTERS' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_filters.php',
'TCPDF_FONTS' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_fonts.php',
'TCPDF_FONT_DATA' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_font_data.php',
'TCPDF_IMAGES' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_images.php',
'TCPDF_IMPORT' => $vendorDir . '/tecnickcom/tcpdf/tcpdf_import.php',
'TCPDF_PARSER' => $vendorDir . '/tecnickcom/tcpdf/tcpdf_parser.php',
'TCPDF_STATIC' => $vendorDir . '/tecnickcom/tcpdf/include/tcpdf_static.php'
);
foreach ($tcpdf_files as $key => $file) {
include_once $file;
}
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Parser.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Document.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Header.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Object.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Page.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Pages.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementArray.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementBoolean.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementString.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementDate.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementHexa.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementMissing.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementName.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementNull.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementNumeric.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementStruct.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Element/ElementXRef.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/StandardEncoding.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/ISOLatin1Encoding.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/ISOLatin9Encoding.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/MacRomanEncoding.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Encoding/WinAnsiEncoding.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontCIDFontType0.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontCIDFontType2.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontTrueType.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontType0.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/Font/FontType1.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/XObject/Form.php";
include_once $vendorDir . "/smalot/pdfparser/src/Smalot/PdfParser/XObject/Image.php";我在Codeigniter库文件夹中创建了一个新文件,该文件名为Pdfparser.php,其内容如下:
defined('BASEPATH') OR exit('No direct script access allowed');
class Pdfparser {
function __construct() {
require_once APPPATH.'/third_party/vendor/autoload.php';
}
}在控制器中,我用以下方式手动加载libray文件:
$this->load->library('pdfparser');问题在于,当我尝试将类实例化时
$parser = new \Smalot\PdfParser\Parser();我得到以下错误:
PHP Fatal error: Class 'Smalot\PdfParser\Parser' not found有什么建议来解决这个问题吗?非常感谢
发布于 2018-10-26 15:24:33
我猜你用的是版本控制?
在本地通过composer安装lib(我看到您刚刚下载并解压缩--这是行不通的)。只需使用vendor的普通目录结构即可。
您应该在项目根目录中有一个composer.json和composer.lock。安装后,composer还创建类映射文件等,它需要这些文件才能找到您的类。
所以。您可以将供应商文件夹放到Git中(根据运行编写器命令的频率,Git会变得有点混乱),或者只需使用像scp这样的工具来安全地复制和部署供应商文件。
希望这能有所帮助!
https://stackoverflow.com/questions/53011675
复制相似问题