drza10046 2016-02-01 07:33
浏览 55
已采纳

在symfony2项目中为服务类命名空间

I am facing one problem I do not know what is a reason of this I add class with location in my project src/ApiMaps/ApiMapBundle with this name space

   <?php
     namespace ApiMaps\ApiMapService;

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

when i give in

       src/config/service.yml

      app.test:  
      class:  ApiMaps\ApiMapService\ApiMapService
      arguments: ["@doctrine.orm.entity_manager"]

and when i run it from some other class for example

 src/ApiMaps/ApiMapBundle/Command/GetApiCommand.php


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

it give me error

Fatal error: Class 'ApiMaps\ApiMapService\ApiMapService' not found in D:\xampp\htdocs\ProjectMapApiData\a pp\cache\dev\appDevDebugProjectContainer.php on line 325 [2016-02-01 08:25:20] php.CRITICAL: Fatal Error: Class 'ApiMaps\ApiMapService\ApiMapService' not found {" type":1,"file":"D:\xampp\htdocs\ProjectMapApiData\app\cache\dev\appDevDebugProjectContainer.php"," line":325,"level":-1,"stack":[]}

[Symfony\Component\Debug\Exception\ClassNotFoundException] Attempted to load class "ApiMapService" from namespace "ApiMaps\ApiMapService". Did you forget a "use" statement for another namespace?

Note-- one thing to mention that when i try to make service from the built-in class of symfony2 classes it does not give me such error. I do know where I need to add the namespace of the class which i recently added with my project that it able to know the class...

  • 写回答

1条回答 默认 最新

  • douhe4608 2016-02-01 07:39
    关注

    You mention that your service in file: src/ApiMaps/ApiMapBundle
    but in config you wrote: ApiMaps\ApiMapService\ApiMapService.

    I think you should house you service in file: src/ApiMaps/ApiMapBundle/ApiMapService/ApiMapService.php,
    take namespace: ApiMaps\ApiMapBundle\ApiMapService
    and write in config: ApiMaps\ApiMapBundle\ApiMapService\ApiMapService.

    Truly believe it'll help you...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下