user3816170
user3816170

Reputation: 321

You have requested a non-existent service

I have problem in my service:

parameters:
   gestion_conge.congeservice.class: Acme\GestionCongeBundle\Manager\CongeManager

services:
gestion_conge.congeservice.class:
    class: %gestion_conge.congeservice.class%
    arguments: [@doctrine.orm.entity_manager, "doctrine.orm.entity_manager", %%]

in my controller i have this:

  public function addAction()
{
    $request = $this->get('request'); // On récupère l'objet request via le service container
    $conge = new Conge(); // On créé notre objet CONGE vierge

    $form = $this->get('form.factory')->create(new CongeType(), $conge); // On bind l'objet CONGE à notre formulaire CongeType

    if ('POST' == $request->getMethod()) { // Si on a posté le formulaire
        $form->bind($request);
            if ($form->isValid()) { // Si le formulaire est valide

                echo 'valide!!';
            $this->get('gestion_conge.congeservice')->saveConge($conge); // On utilise notre Manager pour gérer la sauvegarde de l'objet



            return $this->render('AcmeGestionCongeBundle:Default:index.html.twig');
        }
    }

    return $this->render(('AcmeGestionCongeBundle:Default:add.html.twig'),array('form' => $form->createView(), 'conge' => $conge)); // On passe à Twig l'objet form et notre objet conge
}

I get the error You have requested a non-existent service "gestion_conge.congeservice".

How I can fix that?

Upvotes: 1

Views: 3590

Answers (1)

qooplmao
qooplmao

Reputation: 17759

You have set your class parameter and your service to the same name.

The class parameter should stay as gestion_conge.congeservice.class while your service should be changed to gestion_conge.congeservice.

Update

parameters:
    // Your class parameter
    gestion_conge.congeservice.class: Acme\GestionCongeBundle\Manager\CongeManager

services:
    // Your service name, which is the same as the class parameter,
    // but you are requesting a service called "gestion_conge.congeservice"
    // 1. Service and parameter need to have different names
    // 2. You are not calling the service name that you have set
    gestion_conge.congeservice.class:
        class: %gestion_conge.congeservice.class%
        arguments: [@doctrine.orm.entity_manager, "doctrine.orm.entity_manager", %%]

Upvotes: 2

Related Questions