我对symfony2有个奇怪的问题。 在service.yml我宣布分页服务:Symfony服务声明命名空间
site.paginate_service:
class: "Smestaj\SiteBundle\Services\PaginationService"
arguments:
- "@service_container"
服务看起来是这样的:
namespace Smestaj\SiteBundle\Services;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PaginationService{
protected $cn;
protected $numberOfData;
public function __construct(ContainerInterface $container)
{
$this->cn = $container;
$this->numberOfData = $container->getParameter("limit")['adsPerPage'];
}
问题是,当我称之为service.yml这种服务到另一个服务为dependacy注射
site.ads_service:
class: "Smestaj\SiteBundle\Services\AdsService"
arguments:
- "@doctrine.orm.entity_manager"
- "@service_container"
calls:
- [setPaginate, ["@site.paginate_service"]]
然后我得到这个错误信息:
试图从命名空间“Smestaj \ SiteBundle”加载类“ServicesaginationService”。 你忘记了另一个命名空间的“使用”语句吗?
所以,从这个消息可以清楚看出,symfony试图调用类“ServicesaginationService”。我的班级有Smestaj \ SiteBundle \ Services \ PaginationService。 Symfony以某种方式合并服务和PaginationService名称,并从名称中删除“P”。
如果我将类名更改为AaaService,那么一切正常。
尝试从'class'值中删除引号。 –
将service_container注入到服务本身是一个糟糕的主意。你应该只注入依赖的服务,参数等,但不是服务容器 – rokas