2014-02-18 3 views
2

Почему я получаю эту ошибку при попытке получить ContainerInterface:Ошибка прохождения 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 к методу конструкта:

<?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; 
    } 
    ... 
} 
+0

Пожалуйста, покажите мне свое определение сервиса. – NHG

+0

Да, я думаю, здесь проблема. Я определил следующие параметры: '[@mailer, @translator, @templating, @doctrine]' – Manolo

ответ

5

Возможно, вы имеют неправильное определение услуги. Вы должны вводить все Invitations аргументы, как:

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

Вероятно, вы забыли о @service_container.

КПП. Обратите внимание, что инъекция всего контейнера - плохая идея. Вы должны вводить только необходимые услуги.

Смежные вопросы