public function addAction() { // Récupère tous les produits $productRepo = $this->em->getRepository('Imie\\Entity\\Product'); $products = $productRepo->findAll(); if (!empty($_POST)) { // Si un formulaire est envoyé // Créer un nouveau bug $bug = new Bug(); $prods = $_POST['products']; // array_walk($prods, function(&$value) { $value = (int)($value); }); $prods = $productRepo->getProductsById($prods); $bug->setDescription(htmlentities($_POST['desc'])); // Rempli les objets foreach ($prods as $prod) { $prod->addBug($bug); } // Enregistre le nouveau bug $this->em->persist($bug); $this->em->flush(); header('Location: index.php?controller=bug&action=index'); } $this->render('addBug.php', array('products' => $products)); }
public function addBug(Bug $bug) { $this->bugs[] = $bug; $bug->addProduct($this); return $this; }