Why can't symfony find my auto-loaded class?

 ̄綄美尐妖づ 提交于 2019-12-12 02:36:29

问题


I'm trying to use the php-ga third-party library in my symfony project. I've installed the library in apps/<app>/lib, cleared the cache, and the third-party files are appearing as I would expect in config_autoload.yml.php:

'tracker' => 'C:/wamp/www/apps/api/lib/php-ga/GoogleAnalytics/Tracker.php',
'transaction' => 'C:/wamp/www/apps/api/lib/php-ga/GoogleAnalytics/Transaction.php',
...

However, when I try to use the classes in an action under the same app like so:

use UnitedPrototype\GoogleAnalytics;

public function executeNew(sfWebRequest $request)
{
   $tracker = new GoogleAnalytics\Tracker(...);
   ...

I get an error saying it can't resolve the class:

Fatal error: Class 'UnitedPrototype\GoogleAnalytics\Tracker' not found in C:\wamp\www\apps\api\modules\encoding\actions\actions.class.php

What am I missing?


回答1:


Symfony's autoloader can not load namespaced classes properly. I think you should move the ga lib to lib/vendor/php-ga and use it's own autoloader in config/ProjectConfiguration.class.php (like require_once __DIR__ . '/../lib/vendor/php-ga/autoload.php').



来源:https://stackoverflow.com/questions/12238401/why-cant-symfony-find-my-auto-loaded-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!