Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.73 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Controller;
  4.  
  5. use App\Entity\Product;
  6. use App\Entity\ProductModification;
  7. use PHPUnit\Util\Json;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  9. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14.  
  15. class HomeController extends Controller
  16. {
  17.     /**
  18.      * @Route("/")
  19.      */
  20.     public function home(\Twig_Environment $twig, Request $request)
  21.     {
  22.         $doctrine = $this->getDoctrine();
  23.         $products = $doctrine->getRepository(Product::class)->findAll();
  24.  
  25.         $products = array_chunk($products, 3);
  26.  
  27.         $content = $twig->render('product/index.html.twig', ['products' => $products]);
  28.         $response = new Response();
  29.         $response->setContent($content);
  30.         return $response;
  31.     }
  32.  
  33.     /**
  34.      * @Route("/about")
  35.      */
  36.     public function about(\Twig_Environment $twig)
  37.     {
  38.         $content = $twig->render('other/about.html.twig');
  39.         $response = new Response();
  40.         $response->setContent($content);
  41.         return $response;
  42.     }
  43.  
  44.     /**
  45.      * @Route("/show/{id}", requirements={"id" = "\d+"})
  46.      * @Method({"GET", "POST"})
  47.      */
  48.     public function show(\Twig_Environment $twig, $id, Request $request)
  49.     {
  50.         //$request = $request->request->getInt('radio');
  51.         $request = $request->request->all();
  52.         var_dump($request);
  53.         $doctrine = $this->getDoctrine();
  54.         $product = $doctrine->getRepository(Product::class)->find($id);
  55.         $modification = $product->getModifications()[0];
  56.  
  57.         $content = $twig->render('product/show.html.twig', ['product' => $product, 'modification' => $modification]);
  58.         $response = new Response();
  59.         $response->setContent($content);
  60.         return $response;
  61.     }
  62.  
  63.     /**
  64.      * @Route("/show/{id}/{modification_id}", requirements={"id" = "\d+"})
  65.      * @Method({"GET", "POST"})
  66.      */
  67.     public function showModification(\Twig_Environment $twig, $id, $modification_id)
  68.     {
  69.         $doctrine = $this->getDoctrine();
  70.         $product = $doctrine->getRepository(Product::class)->find($id);
  71.         $modification = $product->getModifications()[0];
  72.         $test = $product->getModifications()[0];
  73.  
  74.         $test = $doctrine->getRepository(ProductModification::class)->find($modification_id);
  75.  
  76.         $content = $twig->render('product/showModification.html.twig', ['product' => $product, 'modification' => $modification, 'test' => $test]);
  77.         $response = new Response();
  78.         $response->setContent($content);
  79.         return $response;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement