I'm using Zend framework 2. I'm trying to call a static function that I imported from a external library. The library was imported correctly.
Now when I'm trying to call the static function within one of the classes he adds my controller path to the function call. Why does he do that?
This is the error I get:
PHP Fatal error: Uncaught Error: Class 'Application\Controller\PHPExcel_IOFactory' not found in /www/zendphp7/htdocs/Ivan/Takalot/module/Application/src/Application/Controller/AuthController.php:177
and this is the function from where the call to the static function is made:
public function getexcelToDB2()
{
$data= array();
$file = __DIR__."/MALMASH_CTM_JOBS_LIST.xml";
$objReader = PHPExcel_IOFactory::createReaderForFile($file);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($file);
}
If you installed the phpoffice/phpexcel
via composer, it should be with a leading "\":
$objReader = \PHPExcel_IOFactory::createReaderForFile($file);
That is how we use the PHPExcel classes in our controllers etc. without a an usage/import of further namespaces.
Otherwise PHP looks in the current namespace (Application\Controller
). You may have a look in the vendor directories of phpoffice/phpexcel
. Their config should hint you to their "correct" namespaces.