symfony为什么找不到我的自动加载的类? [英] Why can't symfony find my auto-loaded class?
问题描述
我正在尝试使用 php-ga 第三方库我的symfony专案.我已经在apps/<app>/lib
中安装了该库,清除了缓存,并且第三方文件出现在 config_autoload.yml.php 中,正如我期望的那样:
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:
致命错误:在C:\ wamp \ www \ apps \ api \ modules \ encoding \ actions \ actions.class.php
Fatal error: Class 'UnitedPrototype\GoogleAnalytics\Tracker' not found in C:\wamp\www\apps\api\modules\encoding\actions\actions.class.php
我想念什么?
推荐答案
Symfony的自动加载器无法正确加载命名空间类.我认为您应该将ga lib移到lib/vendor/php-ga
并在config/ProjectConfiguration.class.php
中使用它自己的自动加载器(例如require_once __DIR__ . '/../lib/vendor/php-ga/autoload.php'
).
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'
).
这篇关于symfony为什么找不到我的自动加载的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!