duanchen6423 2014-02-18 09:56
浏览 267
已采纳

将ContainerInterface作为参数传递时出错

Why am I getting this error when trying to get the ContainerInterface:

ERROR - exception 'ErrorException' with message 'Catchable Fatal Error: Argument 5 passed to Project\InvitationsBundle\Invitations::__construct() must implement interface Symfony\Component\DependencyInjection\ContainerInterface, none given, called in /www/project/app/cache/dev/appDevDebugProjectContainer.php on line 1709 and defined in /www/project/src/Project/InvitationsBundle/Invitations.php line 23' 

And the error comes when adding ContainerInterface to the construct method:

<?php

namespace Pro\InvitationsBundle;

use Pro\CommunityBundle\Entity\Community;
use Pro\InvitationsBundle\Entity\Invitation;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Pro\UserBundle\Entity\User;
use Symfony\Component\DependencyInjection\ContainerInterface;

class Invitations
{
    private $mailer;
    private $translator;
    private $templating;
    private $doctrine;
    private $container;


    function __construct(\Swift_Mailer $mailer, TranslatorInterface $translator, EngineInterface $templating,
        Registry $doctrine, ContainerInterface $container)
    {
        $this->mailer = $mailer;
        $this->translator = $translator;
        $this->templating = $templating;
        $this->doctrine = $doctrine;
        $this->container = $container;
    }
    ...
}
  • 写回答

1条回答 默认 最新

  • douwen8424 2014-02-18 10:03
    关注

    Probably you have wrong service definition. You should inject all of Invitations arguments, like:

    invitations:
        class: Redconvive\InvitationsBundle\Invitations
        arguments: [@mailer, @translator, @templating, @doctrine, @service_container]
    

    Probably you forgot about @service_container.

    Btw. Please notice, that injecting whole container is bad idea. You should inject only necessary services.

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

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集