我在一个名为Model的目录下包含了一组辅助类,在Bundle中。
这是主目录的样子:
OfflineAnalyticsDev
Source Files
/app
/bin
/app
/src
...
/OfflineAnalytics
/OfflineAnalyticsBundle
/Controller
/DependencyInjection
/Model
...
SugarCrmConnect.php
/Resources
/Tests
...
OfflineAnalyticsOfflineAnalyticsBundle.php
/vendor
/web
在SugarCrmConnect.php中我有一个名为SugarCrmConnect的类
namespace OfflineAnalytics\OfflineAnalyticsBundle\Model;
class SugarCrmConnect
{
public static $urlSuffix = "service/v4/soap.php?wsdl";
public static function login($crmHost, $username, $password)
{
...
我试图从我的DefaultController调用Login方法,但它总是显示ClassNotFoundException。我甚至从Model目录/命名空间中调用其他类可以正常工作,但是这个类没有。
namespace OfflineAnalytics\OfflineAnalyticsBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use OfflineAnalytics\OfflineAnalyticsBundle\Model\GoogleAnalyticsHit;
use OfflineAnalytics\OfflineAnalyticsBundle\Model\GoogleAnalyticsUploadService;
use OfflineAnalytics\OfflineAnalyticsBundle\Model\SugarCrmConnect;
class DefaultController extends Controller
{
public function indexAction()
{
$response = new Response();
$hit = new GoogleAnalyticsHit('*******', '******','***', '***','**', '***');
GoogleAnalyticsUploadService::uploadHit($hit);
$loginResult = SugarCrmConnect::login("************", "***", "***");
return $response->setContent('<html><body><h1>'.$loginResult['id'].'</h1></body> </html>');
}
}
我尝试更改文件名以匹配类名和所有内容,但它仍无效。
以下是完整的错误消息:
Attempted to load class "SugarCrmConnect" from namespace "OfflineAnalytics\OfflineAnalyticsBundle\Model"
in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\OfflineAnalyticsDev\src\OfflineAnalytics\OfflineAnalyticsBundle\Controller\DefaultController.php line 19.
Do you need to "use" it from another namespace?
INFO - Matched route "offline_analytics_offline_analytics_homepage" (parameters: "_controller": "OfflineAnalytics\OfflineAnalyticsBundle\Controller\DefaultController::indexAction", "_route": "offline_analytics_offline_analytics_homepage")
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Acme\DemoBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
EMERGENCY - Class 'OfflineAnalytics\OfflineAnalyticsBundle\Model\SugarCrmConnect' not found
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ClassNotFoundException: "Attempted to load class "SugarCrmConnect" from namespace "OfflineAnalytics\OfflineAnalyticsBundle\Model" in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\OfflineAnalyticsDev\src\OfflineAnalytics\OfflineAnalyticsBundle\Controller\DefaultController.php line 19. Do you need to "use" it from another namespace?" at C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\OfflineAnalyticsDev\src\OfflineAnalytics\OfflineAnalyticsBundle\Controller\DefaultController.php line 19
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Acme\DemoBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
有什么想法吗? 我错过了什么吗?
答案 0 :(得分:1)
事实证明我必须在autoload_classmap.php中手动注册我的命名空间,位于vendor / composer /