ronan.lp
ronan.lp

Reputation: 41

Extbase can't use external PHP library

I am building a simple extension to display information on a Google Maps with Typo3. I want to use the following PHP class (http://www.ycerdan.fr/developpement/google-maps-api-v3/) but I can't 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 it's a trivial problem, but I can't make it work despite lot of time searching. Any help or hint are greatly appreciated ;)

General infos

ext_autoloader.php :

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

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

How I use it in my controller

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

The 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 get 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 was messing with the filepath and most importantly i hadn't put a \ before my class instanciation.

Upvotes: 3

Views: 2084

Answers (1)

ronan.lp
ronan.lp

Reputation: 41

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 was messing with the filepath and most importantly i hadn't put a \ before my class instanciation.

Upvotes: 1

Related Questions