问题描述
如何将 PHPExcel 集成到我的Zend应用程序中.
how can I integrate the PHPExcel into my Zend app.
我的实际文件夹结构如下:
My actual folder structure is the following:
/application
controllers
views
etc...
/library
My
Zend
PHPExcel
/public
index.php
我已经使用(在index.php中)包括了我的"库:
I already include 'My' libs by using (in index.php):
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('My_');
现在,我还想在其中一个控制器内使用 PHPExcel ,
Now I also want to use PHPExcel inside one of my controllers like:
$exc = PHPExcel_IOFactory::load('test.xls');
$excelWorksheet = $exc->getActiveSheet();
我该怎么做才能使其工作并摆脱Class 'PHPExcel_IOFactory' not found
异常?
What do I have to do to make it work and get rid of the Class 'PHPExcel_IOFactory' not found
Exception?
谢谢.
-lony
Thank you.
-lony
P.S .:一个简单的$autoloader->registerNamespace('PHPExcel_');
无法正常工作.我测试过了.
P.S.: A simple $autoloader->registerNamespace('PHPExcel_');
is not working. I tested it.
推荐答案
将PHPExcel库放入/library文件夹中,如下所示:
Place the PHPExcel library into the /library folder, like this:
/application
...
/library
/PHPExcel
/PHPExcel.php
接下来,在您的application.ini配置文件中,添加以下内容:
Next, in your application.ini config file, add the following:
autoloaderNamespaces[] = "PHPExcel_"
autoloaderNamespaces[] = "PHPExcel"
应该这样做. Autoloader负责其余的工作,您可以开始使用示例代码来读取Excel文件.
That should do it. Autoloader takes care of the rest, and you can just start using the example code to read an Excel file.
更新:添加了注释者建议的额外的autoloaderNamespace
Update: Added the extra autoloaderNamespace as suggested by commenters
这篇关于将PHPExcel集成到Zend框架中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!