Advertisement
deaphroat

Untitled

Apr 11th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.94 KB | None | 0 0
  1. *********************   MON CONTROLEUR*****************************
  2.  
  3. public function ajouterCategorieAction( Request $request )
  4.     {
  5.         $nombreProduit = 4 ;
  6.        
  7.         $categorie = new Categorie();
  8.        
  9.         $form = $this->createForm(new CategorieType(), $categorie ) ;
  10.        
  11.         $produit = new Produit();
  12.        
  13.         $form2 = $this->createForm(new ProduitType(), $produit);
  14.            
  15.        
  16.        
  17.         /*  
  18.         $test = $this->container->get('chauss_land_stock.Chauss_land_form_produit') ;
  19.        
  20.         $form = $this->createForm( $test->buildForm() , $produit);
  21.    
  22.         $test = $this->container->get('chauss_land_stock.chauss_land_form_produit');
  23.  
  24.         $produit = new Produit;
  25.  
  26.   // On crée le FormBuilder grâce à la méthode du contrôleur
  27.   $form = $this->createForm( $this->container->get('chauss_land_stock.Chauss_land_form_produit') , $produit);
  28.        
  29.        
  30.         $form = $this->container->get('chauss_land_stock.form_produit');
  31.  
  32.         $produit = new Produit;
  33.  
  34.   // On crée le FormBuilder grâce à la méthode du contrôleur
  35.   $form = $this->createForm(new ProduitType, $produit);
  36.  
  37.   */
  38.   // On récupère la requête
  39.        
  40.        
  41.     //$request = $this->getRequest() ;
  42.    
  43.     //echo 'bonjour : '.$request->getMethod();
  44.     // On vérifie qu'elle est de type POST
  45.     if ($request->isMethod('POST'))
  46.         {
  47.        
  48.         echo 'post' ;
  49.        
  50.         if ($form->isValid())
  51.           {
  52.  
  53.             // On redirige vers la page de visualisation de l'article nouvellement créé
  54.             return $this->redirect(  path('Chauss_land_administration_homepage')  ) ;
  55.         }
  56.         else if ($form2->isValid())
  57.         {
  58.             // On redirige vers la page de visualisation de l'article nouvellement créé
  59.             return $this->redirect(  path('Chauss_land_administration_homepage')  ) ;
  60.         }
  61.     }
  62.     else if ($request->isMethod('GET'))
  63.     {
  64.         echo 'get' ;
  65.     }
  66.     else
  67.         {
  68.        
  69.         //echo 'other' ;
  70.     }
  71.    
  72.    
  73.   // On passe la méthode createView() du formulaire à la vue afin qu'elle puisse afficher le formulaire toute seule
  74.   return $this->render('ChaussLandStockBundle:StockController:addCategorie.html.twig', array( 'form' => $form->createView(), 'form2' => $form2->createView(), 'nombreProduit' => $nombreProduit ) ) ;
  75. }
  76.  
  77. }
  78.  
  79.  
  80.  
  81.  
  82. *********************   MON FORM   *****************************
  83.  
  84.  
  85. <div class="well">
  86.    
  87.      Nombre de categorie : {{ nombreProduit }}
  88.    
  89.      
  90.      
  91.      
  92.      <form action="{{ path('Chauss_land_administration_addCategorie') }}" method="post" {{ form_enctype(form2) }}> {{ form_widget(form2) }} <input name="formCat1" type="submit" /> </form>
  93.    
  94. <form action="{{ path('Chauss_land_administration_addCategorie') }}" method="post" {{ form_enctype(form) }}> {{ form_widget(form) }} <input name="formCat" type="submit" /> </form>    
  95. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement