0

want to send an email from my Symfony2 application, this email must contain a link of confirmation and when the user clicks on this link the state of a field in DB to change.

i have this in my controller:

 $message = \Swift_Message::newInstance()
                                    ->setSubject('demande de conge ')
                                    ->setFrom($col->getEmailCollaborateur())
                                    ->setTo($form->get("emailcdp")->getData())
                                    ->setBody($this->render('AcmeBundle:Conge:demandeCongeNormal.html.twig', array('conge' => $conge, 'id'=> $this->getUser()->getId())))
                                    ;
                                    $this->get('mailer')->send($message);

in the twig :

id de collab: {{ id }}

pour confirmer la demande :

{{ url('confirmer_conge' ,{'username': ' id '}) }}

but in the Email i have this :

  http://local.symfony2.com/app_dev.php/confirm/?username=+id+

i want to get the id of user that send the message in another controller for update my DB

in my routing.yml:

 confirmer_conge:
pattern:  /confirm/{username}
defaults: { _controller: acmeBundle:Conge:confirme }

and in the controller i have this function:

 public function confirmeAction()
{return $this->render('acmeBundle:Conge:confirmer.html.twig');
}
lala
  • 111
  • 1
  • 3
  • 11
  • Are you sure that user is logged? – NHG Aug 18 '14 at 10:17
  • yes suree i can open it the problem is how to get the id of user who send the message? – lala Aug 18 '14 at 10:30
  • Ok, so please show me definition of `confirmer_conge` route. – NHG Aug 18 '14 at 10:33
  • confirmer_conge: pattern: /confirm/{username} defaults: { _controller: acmeBundle:Conge:confirme } – lala Aug 18 '14 at 10:36
  • and the controller :: public function confirmeAction() {return $this->render('acmeBundle:Conge:confirmer.html.twig',array('conge'=>$item)); } – lala Aug 18 '14 at 10:37
  • Too big mess in comments. Please update your question with route definition and your controller action code. – NHG Aug 18 '14 at 10:40

1 Answers1

1

Remove the quotes from around id, it is a variable.

{{ url('confirmer_conge', {'username': id}) }}

As for accessing the ID in your controller it should work like this:

public function confirmeAction($username)
    //...
}
Dai
  • 1,510
  • 1
  • 11
  • 12