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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题