调用静态函数 zf2



我正在使用Zend框架2。 我正在尝试调用从外部库导入的静态函数。 库已正确导入。

现在,当我尝试在其中一个类中调用静态函数时,他会将我的控制器路径添加到函数调用中。 他为什么要这样做?

这是我得到的错误:

PHP 致命错误:未捕获错误:类 在 中找不到"应用程序\控制器\PHPExcel_IOFactory"/www/zendphp7/htdocs/Ivan/Takalot/module/Application/src/Application/Controller/AuthController.php:177

这是调用静态函数的函数:

public function getexcelToDB2()
{ 
$data= array();        
$file =  __DIR__."/MALMASH_CTM_JOBS_LIST.xml";       
$objReader = PHPExcel_IOFactory::createReaderForFile($file);        
$objReader->setReadDataOnly(true);       
$objPHPExcel = $objReader->load($file);
}

如果您通过作曲家安装了phpoffice/phpexcel,它应该带有前导"\":

$objReader = PHPExcel_IOFactory::createReaderForFile($file);

这就是我们在控制器等中使用 PHPExcel 类的方式,而无需使用/导入其他命名空间。

否则,PHP 会在当前命名空间 (ApplicationController( 中查找。您可以查看phpoffice/phpexcel的供应商目录。他们的配置应该提示你到他们的"正确"命名空间。

最新更新