我想在 Magento 模块中使用 PclZip 库。我通过包管理器 (libphp-pclzip) 安装了它,但我无法直接在我的模块中使用它,Magento 自动加载器尝试获取该类并失败:
警告:包含(PclZip.php):无法打开流:/home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/lib/Varien/Autoload.php 中没有此类文件或目录第93行
#0 /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'include(PclZip....', '/home/frleq/Dev...', 93, Array)
#1 /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/lib/Varien/Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('PclZip')
#3 [internal function]: spl_autoload_call('PclZip')
#4 /home/frleq/Dev/projets/Compario/magento-community-1.4.2.0/app/code/community/Compario/Connector/Helper/Data.php(8): class_exists('PclZip')
我怎样才能禁用自动加载或让它找到我的库?
谢谢!
最佳答案
快速解决方案是添加包含库的目录以包含路径:
$includePath = 'path/to/lib';
set_include_path(get_include_path() . PS . $includePath);
另一种快速解决方案:
require_once 'path/to/lib/PclZip.php';
但更好的解决方案是更改库的名称,使其对自动加载器可见。它应该在lib目录中,类的名称应该由大写字母开头并用“_”分隔的单词组成。这些单词应该与类文件的目录结构相匹配。 例如:
'path/to/lib/PclZip.php' => Path_To_Lib_PclZip'
关于magento - 如何使用外部库? (Pcl压缩),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4715504/