symfony2 项目中服务 class 的命名空间
namespaceing for service class in symfony2 project
我遇到一个问题我不知道这是什么原因我在我的项目中添加 class 位置 src/ApiMaps/ApiMapBundle 使用此名称 space
<?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"]
当我 运行 它来自其他 class 例如
src/ApiMaps/ApiMapBundle/Command/GetApiCommand.php
class GetApiCommand extends ContainerAwareCommand
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$number = $this->getContainer()->get('app.test');
}
}
它给我错误
致命错误:Class 'ApiMaps\ApiMapService\ApiMapService' 在 D:\xampp\htdocs\ProjectMapApiData\a 中找不到
pp\cache\dev\appDevDebugProjectContainer.php 第 325 行
[2016-02-01 08:25:20] php.CRITICAL: 致命错误: Class 'ApiMaps\ApiMapService\ApiMapService' 未找到 {"
输入":1,"file":"D:\xampp\htdocs\ProjectMapApiData\app\cache\dev\appDevDebugProjectContainer.php","
行":325,"level":-1,"stack":[]}
[Symfony\Component\Debug\Exception\ClassNotFoundException]
试图从名称space "ApiMaps\ApiMapService" 加载class "ApiMapService"。
您是否忘记了另一个名称 space 的 "use" 语句?
注意--
值得一提的是,当我尝试从 symfony2 classes 的内置 class 提供服务时,它不会给我这样的错误。我知道我需要在哪里添加 class 的名称 space,我最近在我的项目中添加了它,它能够知道 class...
您在文件中提到您的服务:
src/ApiMaps/ApiMapBundle
但在配置中你写道:
ApiMaps\ApiMapService\ApiMapService
.
我认为你应该将你的服务放在文件中:src/ApiMaps/ApiMapBundle/ApiMapService/ApiMapService.php
,
获取命名空间:ApiMaps\ApiMapBundle\ApiMapService
并在配置中写入:ApiMaps\ApiMapBundle\ApiMapService\ApiMapService
.
坚信它会帮助你...
我遇到一个问题我不知道这是什么原因我在我的项目中添加 class 位置 src/ApiMaps/ApiMapBundle 使用此名称 space
<?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"]
当我 运行 它来自其他 class 例如
src/ApiMaps/ApiMapBundle/Command/GetApiCommand.php
class GetApiCommand extends ContainerAwareCommand
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$number = $this->getContainer()->get('app.test');
}
}
它给我错误
致命错误:Class 'ApiMaps\ApiMapService\ApiMapService' 在 D:\xampp\htdocs\ProjectMapApiData\a 中找不到 pp\cache\dev\appDevDebugProjectContainer.php 第 325 行 [2016-02-01 08:25:20] php.CRITICAL: 致命错误: Class 'ApiMaps\ApiMapService\ApiMapService' 未找到 {" 输入":1,"file":"D:\xampp\htdocs\ProjectMapApiData\app\cache\dev\appDevDebugProjectContainer.php"," 行":325,"level":-1,"stack":[]}
[Symfony\Component\Debug\Exception\ClassNotFoundException] 试图从名称space "ApiMaps\ApiMapService" 加载class "ApiMapService"。 您是否忘记了另一个名称 space 的 "use" 语句?
注意-- 值得一提的是,当我尝试从 symfony2 classes 的内置 class 提供服务时,它不会给我这样的错误。我知道我需要在哪里添加 class 的名称 space,我最近在我的项目中添加了它,它能够知道 class...
您在文件中提到您的服务:
src/ApiMaps/ApiMapBundle
但在配置中你写道:
ApiMaps\ApiMapService\ApiMapService
.
我认为你应该将你的服务放在文件中:src/ApiMaps/ApiMapBundle/ApiMapService/ApiMapService.php
,
获取命名空间:ApiMaps\ApiMapBundle\ApiMapService
并在配置中写入:ApiMaps\ApiMapBundle\ApiMapService\ApiMapService
.
坚信它会帮助你...