Bonjour ,

J'ai cette erreur lorsque je supprime un élément recette :



Voici le code de mon fichier recette.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
 
namespace ShopandCook\SiteBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
 
/**
* @ORM\Entity(repositoryClass="ShopandCook\SiteBundle\Entity\Repository\RecettesRepository")
* @ORM\Table(name="recettes")
*/
class Recette
{
 
    // Un tableau pour gérer les libellés facilement d'une recette
    public static $_statut = array(
        'attente' => 'en_attente',
        'creation' => 'creation_en_cours',
        'publiee' => 'publiee'
    );
 
    /**
     * @ORM\Column(name="id_recette", type="integer")
     * @ORM\Id 
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id_recette;
 
    /**
     * @ORM\Column(name="titre", type="string", length=255)
     */
    protected $titre;
 
    /**
     * @ORM\Column(name="description", type="text")
     */
    protected $description;
 
    /**
     * @ORM\OneToMany(targetEntity="RecetteIngredient", mappedBy="recette")
     * @ORM\JoinColumn(name="id_ingredient", referencedColumnName="id_ingredient")
     */
    protected $ingredients;
 
    /**
     * @ORM\Column(name="etapes", type="text")
     */
    protected $etapes;
 
    /**
     * @ORM\Column(name="evaluation", type="integer")
     */
    protected $evaluation;
 
    /**
     * @ORM\Column(name="statut", type="string", length=255)
     */
    protected $statut;
 
    /**
     * @ORM\ManyToOne(targetEntity="User", inversedBy="recettes")
     * @ORM\JoinColumn(name="id_user",referencedColumnName="id_user")     
     */
    protected $auteur;
 
    /**
     * @ORM\Column(name="date_proposition", type="datetime")
     */
    protected $dateProposition;
 
    /**
     * @ORM\Column(name="date_publication", type="datetime", nullable=true)
     */
    protected $datePublication;
 
    /**
     * @ORM\Column(name="type", type="string", length=255)
     */
    protected $type;
 
    /**
     * @ORM\Column(name="calories", type="integer")
     */
    protected $calories;	
 
    /**
     * @ORM\Column(name="tpsPreparation", type="integer")
     */
    protected $tpsPreparation;
 
    /**
     * @ORM\Column(name="tpsCuisson", type="integer")
     */
    protected $tpsCuisson;
 
    /**
     * @ORM\Column(name="difficulte", type="integer")
     */
    protected $difficulte;
 
    /**
     * @ORM\Column(name="nbPersonnes", type="integer")
     */
    protected $nbPersonnes;
 
    /**
     * @ORM\Column(name="image", type="string", length=255, nullable=true)
     */
    protected $image;
 
    /**
     * @ORM\Column(name="video", type="string", length=255,nullable=true)
     */
    protected $video;
 
    /**
     * @ORM\Column(name="publiee", type="boolean")
     */
    protected $publiee = false;
 
    /**
     * @ORM\OneToMany(targetEntity="Commentaires", mappedBy="recette",cascade={"remove", "persist"})
     * @ORM\JoinColumn(name="id_commentaire", referencedColumnName="id_commentaire")
     */
    protected $commentaires;
 
    /**
     * @ORM\OneToMany(targetEntity="Notes", mappedBy="recette",cascade={"remove", "persist"})
     */
    protected $notes;
 
 
    public function getId(){
            return $this->id_recette;
    }
 
    public function setId($id)
    {
            $this->id_recette = $id;
            return $this;
    }
    public function getTitre(){
            return $this->titre;
    }
 
    public function setTitre($titre)
    {
            $this->titre = $titre;
            return $this;
    }
    public function getDescription(){
            return $this->description;
    }
 
    public function setDescription($description)
    {
            $this->description = $description;
            return $this;
    }
 
    public function getIngredients(){
            return $this->ingredients;
    }
 
    public function setIngredients($ingredients)
    {
            $this->ingredients = $ingredients;
            return $this;
    }
 
    public function getEtapes(){
            return $this->etapes;
    }
 
    public function setEtapes($etapes)
    {
            $this->etapes = $etapes;
            return $this;
    }
    public function getEvaluation(){
            return $this->evaluation;
    }
 
    public function setEvaluation($evaluation)
    {
            $this->evaluation = $evaluation;
            return $this;
    }
    public function getStatut(){
            return $this->statut;
    }
 
    public function setStatut($statut)
    {
            $this->statut = $statut;
            return $this;
    }
    public function getAuteur(){
            return $this->auteur;
    }
 
    public function setAuteur($auteur)
    {
            $this->auteur = $auteur;
            return $this;
    }
    public function getDateProposition(){
            return $this->dateProposition;
    }
 
    public function setDateProposition($dateProposition)
    {
            $this->dateProposition = $dateProposition;
            return $this;
    }
 
    public function getDatePublication()
    {
            return $this->datePublication;
    }
 
    public function setDatePublication($datePublication)
    {
            $this->datePublication = $datePublication;
            return $this;
    }
 
    public function getType(){
            return $this->type;
    }
 
    public function setType($type)
    {
            $this->type = $type;
            return $this;
    }
    public function getCalories(){
            return $this->calories;
    }
 
    public function setCalories($calories)
    {
            $this->calories = $calories;
            return $this;
    }
    public function getTpsPreparation(){
            return $this->tpsPreparation;
    }
 
    public function setTpsPreparation($tpsPreparation)
    {
            $this->tpsPreparation = $tpsPreparation;
            return $this;
    }
    public function getTpsCuisson(){
            return $this->tpsCuisson;
    }
 
    public function setTpsCuisson($tpsCuisson)
    {
            $this->tpsCuisson = $tpsCuisson;
            return $this;
    }
    public function getDifficulte(){
            return $this->difficulte;
    }
 
    public function setDifficulte($difficulte)
    {
            $this->difficulte = $difficulte;
            return $this;
    }
    public function getNbPersonnes(){
            return $this->nbPersonnes;
    }
 
    public function setNbPersonnes($nbPersonnes)
    {
            $this->nbPersonnes = $nbPersonnes;
            return $this;
    }
 
    public function getImage(){
            return $this->image;
    }
 
    public function setImage($imageURL)
    {
            $this->image = $imageURL;
            return $this;
    }
    public function getVideo(){
            return $this->video;
    }
 
    public function setVideo($videoURL)
    {
            $this->video = $videoURL;
            return $this;
    }
    public function getCommentaires(){
            return $this->commentaires;
    }
 
    public function setCommentaires($commentaires)
    {
            $this->commentaires = $commentaires;
            return $this;
    }
 
    public function getNotes()
    {
        return $this->notes;
    }
 
    public function setNotes($notes)
    {
        $this->notes = $notes;
        return $this;
    }
 
    public function getPubliee()
    {
        return $this->publiee;
    }
 
    public function setPubliee($publiee)
    {
        $this->publiee = $publiee;
        return $this;
    }
}
?>


Ici est le code de mon fichier recettecontroller.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
 
namespace ShopandCook\SiteBundle\Controller\Admin;
 
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
 
use Symfony\Component\HttpFoundation\Request;
 
use ShopandCook\SiteBundle\Form\RecettesType;
use ShopandCook\SiteBundle\Entity\Recette;
use ShopandCook\SiteBundle\Entity\RecetteIngredient;
use ShopandCook\SiteBundle\Entity\Categorie;
use ShopandCook\SiteBundle\Entity\Ingredient;
 
/**
 * @Route("/admin/recettes")
 */
class RecetteController extends Controller
{
    /**
     * @Route("", name="admin_recettes")
     * @Template()
     */
 
    public function indexAction()
    {
    	$em = $this->getDoctrine()->getEntityManager();
		$recettes = $em->getRepository('ShopandCookSiteBundle:Recette')->findBy(array('statut'=>Recette::$_statut["publiee"]));;
 
		$recettes_attente = $em->getRepository('ShopandCookSiteBundle:Recette')->findBy(array('statut'=> Recette::$_statut["attente"]));
 
		return array('recettes_attente' => $recettes_attente, 'recettes' => $recettes);
    }
 
/**
     * @Route("/proposer/informations", name="admin_ajout_recette")
     * @Template()
     */
    public function proposerInformationsRecetteAction(Request $request) {
 
        $user = $this->container->get('security.context')->getToken()->getUser();
 
        $recette = new Recette();
 
        $form = $this->createForm(new RecettesType(), $recette);
 
        if('POST' === $request->getMethod())
        {
            $form->bindRequest($request);			      
 
            if ($form->isvalid()) 
            {                    
                $recette->setDateProposition(new \DateTime());
                $recette->setAuteur($user);
                $recette->setStatut(Recette::$_statut['creation']);
                $recette->setEvaluation(0);
                $em = $this->getDoctrine()->getEntityManager();
                $em->persist($recette);
                $em->flush();
                //$request->getSession()->setFlash('success', 'La recette a été ajouté. Elle nécessitera une validation d\'un administrateur avant d\'être visible.');
                return $this->redirect($this->generateUrl('admin_ajout_recette_ingredients', array('id_recette' => $recette->getId())));
            }
        }
        return array('form' => $form->createView());
    }
 
 
	/**
	 * @Route("/modifier/{id}", name="admin_modifier_recette")
	 * @Template()
	 */
	public function modifierRecetteAction(Request $request, $id)
	{
		$em = $this->getDoctrine()->getEntityManager();
		$recette = $em->getRepository('ShopandCookSiteBundle:Recette')->find($id);
		$form = $this->createForm(new RecettesType(), $recette);
 
		if($request->isMethod('post'))
	    {
	      $form->bind($request);
		  if($form->isvalid())
		  {			
			$em->persist($recette);
			$em->flush();
			// Insertion de la recette dans la base de données
			$this->get('session')->setFlash('success', 'La recette a bien été modifiée !');
			return $this->redirect($this->generateUrl('admin_recettes'));
		  }
	    }
		return array('form' => $form->createView());
	}
 
	   /**
     	* @Route("/proposer/{id_recette}/ingredients", name="admin_ajout_recette_ingredients")
     	* @Template()
     	*/
    public function choisirIngredientCreationRecetteAction(Request $request, $id_recette) 
    {
        $em = $this->getDoctrine()->getEntityManager();
 
        $recette = $em->getRepository("ShopandCookSiteBundle:Recette")->find($id_recette);
        $user = $this->container->get('security.context')->getToken()->getUser();
 
        if($recette->getAuteur()->getId() !== $user->getId())
        {
            $request->getSession()->setFlash('notice', 'Vous n\'avez pas le droit d\'accéder à cette étape.');
            return $this->redirect($this->generateUrl('admin_recettes'));
        }
 
        $unites = $em->getRepository("ShopandCookSiteBundle:UniteMesure")->findAll();
 
        // Quand on valide la sélection des ingrédients
        if('POST' === $request->getMethod())
        {               
            $obj_ingredients = $request->request->get("id_ingredient_tableau");
 
            foreach($obj_ingredients as $id_ingredient_tableau)
            {
                $ingredient = $em->getRepository("ShopandCookSiteBundle:Ingredient")->find($id_ingredient_tableau);
                $quantite_ingredient = $request->request->get("quantite_".$id_ingredient_tableau);
                $id_unite_ingredient = $request->request->get("id_unite_".$id_ingredient_tableau);
                $unitemesure = $em->getRepository("ShopandCookSiteBundle:UniteMesure")->find($id_unite_ingredient);
                $recette_ingredient = new RecetteIngredient();
                $recette_ingredient
                        ->setIngredient($ingredient)
                        ->setRecette($recette)
                        ->setUnite($unitemesure)
                        ->setQuantite($quantite_ingredient);
 
                /*echo '<pre>';
                \Doctrine\Common\Util\Debug::dump($recette_ingredient);
                exit;*/
 
                $em->persist($recette_ingredient);
                $em->flush();
            }
 
            $recette->setStatut(Recette::$_statut["publiee"]);
            $em->flush();
 
            $request->getSession()->setFlash('success', 'La recette a été ajouté. Elle nécessitera une validation d\'un administrateur avant d\'être visible. Vous pouvez suivre le statut de validation dans la partie "Mes recettes" de votre compte.');
            return $this->redirect($this->generateUrl('admin_recettes'));
        }
 
        return array(
            'recette' => $recette,
            'unites' => $unites
        );
    }
 
    /**
     * @Route("/ajax/ingredient/autocomplete", name="admin_ajax_ingredient_autocomplete")
     */
    public function choixIngredientAjaxAction(Request $request)
    {
        // récupération des ingrédients selon le texte saisi par l'utilisateur
        $value = $request->get('donnees');
        $em = $this->getDoctrine()->getEntityManager();
        $ingredients = $em->getRepository('ShopandCookSiteBundle:Ingredient')->getIngredientsByTitre($value);
 
        return new Response(json_encode($ingredients));
    }
 
    /**
     * @Route("/ajax/ingredient/ajouter", name="admin_ajax_ingredient_ajouter")
     * @Template("ShopandCookSiteBundle:Recette:choixIngredientTableau.html.twig")
     */
    public function ajouterIngredientTableauAjaxAction(Request $request)
    {
        $lib = $request->request->get("libelle");
        $id_ingredient = $request->request->get("id_ingredient");
        $quantite = $request->request->get("quantite");
        $id_unite = $request->request->get("id_unite");
        $unite = $request->request->get("libelle_unite");
 
        return array(
            'libelle' => $lib,
            'quantite' => $quantite,
            'id_ingredient' => $id_ingredient,
            'id_unite' => $id_unite,
            'libelle_unite' => $unite
        );
    }
	/**
	 * @Route("/supprimer/{id}", name="admin_supprimer_recette")
	 * @Template()
	 */
	public function supprimerRecetteAction(Request $request, $id)
	{
		$em = $this->getDoctrine()->getEntityManager();
 
 
		// $Recette_ingredients = $em->getRepository('ShopandCookSiteBundle:Recette_ingredients')->find($id);
		// $em->removeElement($Recette_ingredients); //test
		////$em->remove($Recette_ingredients);
		// $em->flush();
		// $commentaires = $em->getRepository('ShopandCookSiteBundle:commentaires')->find($id);
		// $em->removeElement($commentaires); //test
		////$em->remove($commentaires);
		// $em->flush();
		// $notes = $em->getRepository('ShopandCookSiteBundle:notes')->find($id);
		// $em->removeElement($notes); //test
		////$em->remove($notes);
		// $em->flush(); 
 
 
 
 
		$recette = $em->getRepository('ShopandCookSiteBundle:Recette')->find($id);
		$em->remove($recette);
		$em->flush();
 
		$this->get('session')->setFlash('success', 'La recette a bien été supprimée !');
 
		return $this->redirect($this->generateUrl('admin_recettes'));
	}
 
	/**
	 * @Route("/valider/{id}", name="admin_valider_recette")
	 * @Template()
	 */
	public function validerRecetteAction($id)
	{
		$em = $this->getDoctrine()->getEntityManager();
		$recette = $em->getRepository('ShopandCookSiteBundle:Recette')->find($id);
 
		if (!$recette) 
		{
			throw $this->createNotFoundException('La recette n existe pas avec l id '.$id);
		}
 
		$recette->setStatut('publiee');
        $recette->setPubliee(true);
		$em->flush();
 
		return $this->redirect($this->generateUrl('admin_recettes'));
	}
 
 
}
La table recette depend de la table "recette_ingredient" et de la table "notes" et de la table "commentaires".

Je suis bloqué , pouvez vous m'aider à supprimé en cascade ?


Merci pour vos conseils et votre aide,



Lionceau,