问题
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