为什么在尝试获取以下错误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'
当添加ContainerInterface
到construct方法时,就会出现错误:
<?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;
}
...
}
可能您的服务定义有误。您应该注入所有Invitations
参数,例如:
invitations:
class: Redconvive\InvitationsBundle\Invitations
arguments: [@mailer, @translator, @templating, @doctrine, @service_container]
可能您忘记了@service_container
。
顺便说一句。请注意,注入整个容器不是一个好主意。您应该只注入必要的服务。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句