Symfony2项目中服务类的命名空间


namespaceing for service class in symfony2 project

我面临一个我不知道是什么原因的问题,我在我的项目中添加了带有位置的类 src/ApiMaps/ApiMapBundle 与此名称空间

   <?php
     namespace ApiMaps'ApiMapService;
  class ApiMapService {
  private $transport;
   public function __construct() {
    $this->transport = 'sendmail';
  }
// ...
}

当我屈服时

       src/config/service.yml
      app.test:  
      class:  ApiMaps'ApiMapService'ApiMapService
      arguments: ["@doctrine.orm.entity_manager"]

例如,当我从其他类运行它时

 src/ApiMaps/ApiMapBundle/Command/GetApiCommand.php

 class GetApiCommand extends ContainerAwareCommand
   {  
   protected function execute(InputInterface $input, OutputInterface $output)
     {
   $number = $this->getContainer()->get('app.test');
     }
   }

它给了我错误

致命错误:在 D:''xampp''htdocs''ProjectMapApiData''a 中找不到类"ApiMaps''ApiMapService''ApiMapService"pp''cache''dev''appDevDebugProjectContainer.php 在第 325 行[2016-02-01 08:25:20] php.严重:致命错误:找不到类"ApiMaps''ApiMapService''ApiMapService" {"type":1,"file":"D:''xampp''htdocs''ProjectMapApiData''app''cache''dev''appDevDebugProjectContainer.php","行":325,"级别":-1,"堆栈":[]}

[Symfony''Component''Debug''Exception''ClassNotFoundException] 试图从命名空间"ApiMaps''ApiMapService"加载类"ApiMapService"。 您是否忘记了另一个命名空间的"use"语句?

注意--值得一提的是,当我尝试从 Symfony2 类的内置类提供服务时,它不会给我这样的错误。我确实知道我需要在哪里添加我最近在我的项目中添加的类的命名空间,它能够知道该类......

您在文件中提到您的服务: src/ApiMaps/ApiMapBundle
但是在配置中你写道: ApiMaps'ApiMapService'ApiMapService .

我认为您应该将服务存放在文件中:src/ApiMaps/ApiMapBundle/ApiMapService/ApiMapService.php
获取命名空间:ApiMaps'ApiMapBundle'ApiMapService
并写入配置:ApiMaps'ApiMapBundle'ApiMapService'ApiMapService .

真的相信它会帮助你...