src/Controller/CategoryController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\PlanRepository;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class CategoryController extends AbstractController
  8. {
  9. #[Route('/category/{slug}', name: 'app_category')]
  10. public function show(string $slug, PlanRepository $planRepository): Response
  11. {
  12. // Convert slugs like 'xeon-kvm' to 'Xeon KVM Server' if needed, or better:
  13. // just search the DB where category = $slug, or name contains '$slug' logic.
  14. // For flexibility, let's map the slugs to actual human titles.
  15. $slugToCategory = [
  16. 'xeon-kvm' => 'Xeon KVM Server',
  17. 'ryzen-kvm' => 'Ryzen KVM Server',
  18. 'epyc-kvm' => 'Epyc KVM Server',
  19. 'ipv6-kvm' => 'IPv6 Only KVM',
  20. 'intel-dedicated' => 'Intel Dedicated',
  21. 'amd-dedicated' => 'AMD Dedicated',
  22. 'sale-dedicated' => 'Sale Dedicated',
  23. 'gameserver' => 'Gameserver',
  24. 'webhosting' => 'Webhosting',
  25. 'nextcloud' => 'Nextcloud Hosting',
  26. 'colocation' => 'Colocation',
  27. 'object-storage' => 'Object Storage'
  28. ];
  29. $title = $slugToCategory[$slug] ?? ucfirst(str_replace('-', ' ', $slug));
  30. // Find plans where the category exactly matches the title.
  31. $plans = $planRepository->findBy(['category' => $title], ['price' => 'ASC']);
  32. return $this->render('category/index.html.twig', [
  33. 'slug' => $slug,
  34. 'title' => $title,
  35. 'plans' => $plans,
  36. ]);
  37. }
  38. }