I have a controller in which I want to set up a log where a specific user can see a mission's history (something that would look like ( {user} set the mission as {mission status}, whether he accepts a mission or not. I would like to set this "status" inside an array so when I make it show up, it would look like a list of the events.
So far, here's how it looks:
/**
* @Route("/accept/{id}", name="mission_accept")
* @Method("POST")
*/
public function acceptAction(Request $request, Mission $mission){
$form = $this->acceptMission($mission);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$user = $this->container->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$mission->setStatut("filled");
$mission->setAppliedSchool($user->getEcole());
$history = $mission->getHistory();
$mission->setHistorique(array_push($history, 'Mission '.$mission->getStatut().' by'. $mission->getAppliedSchool()));
$em->persist($mission);
$em->flush();
}
return $this->redirectToRoute('mission_index');
}
"getAppliedSchool" gets the user that has changed the mission's status by something else by accepting or declining the mission.
My issue is that when I try to save this status, everything works fine except for the array, where I go from the default value in the database ( a:0:{}
) to something like this: a:2
, and I don't know why. I think I'm doing something wrong but I can't tell where and how.
Any idea ?
The thing is that array_push
doesn't return an array. So just change your code a bit:
array_push($history, 'Mission '.$mission->getStatut().' by'. $mission->getAppliedSchool());
$mission->setHistorique($history);