Extbase无法使用外部PHP库

时间:2015-06-02 09:17:32

标签: typo3 extbase

我正在构建一个简单的扩展程序,以便在使用Typo3的Google地图上显示信息。 我想使用以下PHP类(http://www.ycerdan.fr/developpement/google-maps-api-v3/)但我无法在我的控制器中使用它。

我尝试在我的控制器中使用自动加载和require_once,但我只是得到PHP或Typo3错误。

我认为这是一个微不足道的问题,但是尽管有很多时间搜索,但我无法使其发挥作用。 非常感谢任何帮助或提示;)

一般信息

  • 供应商名称:CLICmap

  • 分机名称:clicmap

  • 班级位置:资源/私人/ PHP

ext_autoloader.php:

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

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

我如何在我的控制器中使用它

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

PHP错误:

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.

尝试require_once:

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

我收到以下PHP错误:

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

编辑:已解决

解决我在控制器中出现问题的代码:

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

我正在弄乱文件路径,最重要的是我没有在我的班级实例之前提出一个\。

1 个答案:

答案 0 :(得分:1)

解决我在控制器中出现问题的代码:

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

我正在弄乱文件路径,最重要的是我没有在我的班级实例之前提出一个\。