我的服务有问题:
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", %%]
在我的控制器中我有这个:
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
}
我收到错误您已请求不存在的服务" gestion_conge.congeservice"。
我如何解决这个问题?
答案 0 :(得分:2)
您已将类参数和服务设置为相同名称。
类参数应保持为gestion_conge.congeservice.class
,而您的服务应更改为gestion_conge.congeservice
。
<强>更新强>
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", %%]