I followed this to create a button to call a function but it is not working. No error message and the redirect works. But the order status doesn't change.... Can anyone find what is the wrong with it?
my button in twig
<a href="{{ path('change_order_status', { id : NewOrder.id }) }}" class="btn btn-primary">change status</a>
my controller
/**
* @param order $target
*
* @Route("/admin/order", name="change_order_status")
*/
public function changeOrderStatus(order $target)
{
echo dump($target);
if (!$target instanceof Order) {
return;
}
$OrderStatus = $this->orderStatusRepository->find(OrderStatus::IN_PROGRESS);
$target->setOrderStatus($OrderStatus);
$target->setOrderDate(new \DateTime());
$em = $this->getEntityManager();
$em->persist($Order);
$em->flush();
}
}
There are multiple flaws in the code:
$target
is type-hinted with order
but the object is of type Order
(case matters!)
instanceof
check if redundant$Order
but not $target
so the variable name is wrong