public function create($title, $content, User $user) { $article = new Article(); $valide = $article->setContent($content); if ($valide === true) { $valide = $article->setUser($user); if ($valide === true) { $content = mysqli_real_escape_string($this->db, $article->getContent()); $id_user = $article->getId_user(); $query = "INSERT INTO article (title, content, id_user) VALUES('" . $title . "', '" . $content . "', '" . $id_user . "')"; $res = mysqli_query($this->db, $query); if ($res) { $id = mysqli_insert_id($this->db); if ($id) { return $this->findById($id); } else { return "Internal server error"; } } else { echo 'test14'; exit; return mysqli_error($this->db); } } else { return $valide; } } else { return $valide; } }
public function testAction() { $article = new Article(); $article->setTitle("L'histoire d'un bon weekend !"); $article->setContent("Le weekend était vraiment trop bien !"); $article->setCreatedAt(new \DateTime('now', new \DateTimeZone('Europe/Paris'))); $article->setEnabled(true); $em = $this->getDoctrine()->getManager(); $user = $this->getUser(); if ($user) { $article->setUser($user); } $em->persist($article); $em->flush(); $url = $this->generateUrl('suplol_user_homepage'); return $this->redirect($url); }