0
I need to change the status of an object registered in the database, from the ID of this object, once I click the corresponding button. How do I move on to my role in controller the ID of that object?
What I should insert into my HTML button?
HTML button:
<button type="submit" class="btn btn-outline-danger" name="acao" value="desligar" id="{{ cooperado.getId() }}">Desligar</button>
Function in the controller:
public function acaoBotoes()
{
switch ($_POST['acao']) {
case 'desligar':
$id = $_POST['???'];
$em = $this->getDoctrine()->getManager();
$cooperado = $em->getRepository(Cooperado::class)->find($id);
$cooperado->setStatus('DE')
->setDataDesligamento(\DateTime::createFromFormat('Y-m-d', date('Y-m-d')));
$em->flush();
return $this->redirectToRoute('cooperados');
break;
In the $id variable I need to get the ID from the view button, then handle the status change function of this object. This case will handle the status change. I need to click "off" and change the status of an Active to Off cooperator, as below:
Excellent, Marcelo. That worked perfectly. Thank you!
– Victor Moraes