Extbase cannot use external PHP library

I am creating a simple extension to display information on Google Maps using Typo3. I want to use the following PHP class ( http://www.ycerdan.fr/developpement/google-maps-api-v3/ ), but I cannot use it in my controller.

I tried to use autoloading and require_once in my controller, but I just get PHP or Typo3 errors.

I guess this is a trivial problem, but I can't seem to get it to work despite a lot of time searching. Any help or hint is greatly appreciated;)

general information

  • Provider name: CLICmap

  • Extension name: clicmap

  • Class location: resources / private / php

ext_autoloader.php:

$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('clicmap');

return array(   
    'gmaps' => $extensionPath.'Resources/Private/PHP/GoogleMapAPIv3.class.php',
);  

      

How do I use it in my controller

public function listAction() {
    $maps = $this->mapRepository->findAll();
    $gmaps = $this->objectManager->get('gmaps');
    $this->view->assign('maps', $maps);
}

      

PHP error:

Uncaught TYPO3 Exception
#1289386765: Could not analyse class:gmaps maybe not loaded or no autoloader? (More information)

TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException thrown in file
/var/www/html/ftypo3/typo3/sysext/extbase/Classes/Object/Container/ClassInfoFactory.php in line 37.

      

Trying require_once:

$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('clicmap');
require_once($extensionPath . 'Ressources/Private/PHP/GoogleMapAPIv3.class.php');

      

I am getting the following PHP error:

Warning: Uncaught exception 'TYPO3\CMS\Core\Error\Exception' with message 'PHP Warning: require_once(/var/www/html/ftypo3-fluid/typo3conf/ext/clicmap/Ressources/Private/PHP/GoogleMapAPIv3.class.php): failed to open stream: No such file or directory in /var/www/html/ftypo3/typo3conf/ext/clicmap/Classes/Controller/MapController.php line 52' in /var/www/html/ftypo3/typo3/sysext/core/Classes/Error/ErrorHandler.php:101 Stack trace: #0 /var/www/html/ftypo3/typo3conf/ext/clicmap/Classes/Controller/MapController.php(52): TYPO3\CMS\Core\Error\ErrorHandler->handleError(2, 'require_once(/v...', '/var/www/html/f...', 52, Array) #1 /var/www/html/ftypo3/typo3conf/ext/clicmap/Classes/Controller/MapController.php(52): CLICmap\Clicmap\Controller\MapController::listAction() #2 [internal function]: CLICmap\Clicmap\Controller\MapController->listAction() #3 /var/www/html/ftypo3/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php(286): call_user_func_array(Array, Array) #4 /var/www/html/ftypo3/typo3/sysext/extbase/Classes/Mvc/ in /var/www/html/ftypo3/typo3/sysext/core/Classes/Error/ErrorHandler.php on line 101

Fatal error: CLICmap\Clicmap\Controller\MapController::listAction(): Failed opening required '/var/www/html/ftypo3-fluid/typo3conf/ext/clicmap/Ressources/Private/PHP/GoogleMapAPIv3.class.php' (include_path='/var/www/html/ftypo3-fluid/typo3/contrib/pear/:.:/usr/share/php:/usr/share/pear') in /var/www/html/ftypo3/typo3conf/ext/clicmap/Classes/Controller/MapController.php on line 52

      

EDIT: Solved

The code that solved my problem in the controller:

require_once(PATH_site . 'typo3conf/ext/clicmap/Resources/Private/PHP/GoogleMapAPIv3.class.php');//OK
$gmap = new \GoogleMapAPI();

      

I fiddled with the filepath and most importantly, I didn’t put a pre-install of my class.

+3


source to share


1 answer


The code that solved my problem in the controller:

require_once(PATH_site . 'typo3conf/ext/clicmap/Resources/Private/PHP/GoogleMapAPIv3.class.php');//OK
$gmap = new \GoogleMapAPI();

      



I fiddled with the filepath and most importantly, I didn’t put a pre-install of my class.

+1


source







All Articles