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...

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

报告相同问题?

悬赏问题

  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?