src/Controller/ShortenUrlsController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use App\Repository\ShortUrlsRepository;
  8. use App\Entity\ShortUrls;
  9. use App\Entity\Users;
  10. class ShortenUrlsController extends AbstractController
  11. {
  12.     /**
  13.      * @Route("/product", name="app_product")
  14.      */
  15.     public function index(ShortUrlsRepository $repository): Response
  16.     {
  17.         // $shortened_urls = $repository->findAll();
  18.         $shortened_urls = $repository->findBy([], ['id' => 'DESC']);
  19.         return $this->render('shortenurls/index.html.twig', [
  20.             'shortened_urls' => $shortened_urls,
  21.         ]);
  22.     }
  23.     public function show($id, ShortUrlsRepository $repository): Response
  24.     {
  25.         $shortened_url = $repository->find($id);
  26.         if ($shortened_url === null) {
  27.             throw $this->createNotFoundException('No details found');
  28.         }
  29.         return $this->render('shortenurls/show.html.twig', [
  30.             'shortened_url' => $shortened_url
  31.         ]);
  32.     }
  33. }