Untitled
unknown
php
a year ago
1.1 kB
3
Indexable
class HomeController extends AbstractController { #[Route('/api/home', name: 'api_home')] public function index(EntityManagerInterface $entityManager): JsonResponse { $customerRepository = $entityManager->getRepository(Customer::class); $customers = $customerRepository->findAll(); // Prepare an array of customer data to be returned as JSON $customerData = []; foreach ($customers as $customer) { $customerData[] = [ 'id' => $customer->getId(), 'name' => $customer->getName(), 'email' => $customer->getEmail(), // Add other fields as needed ]; } return $this->json($customerData, 200); } #[Route('/home', name: 'app_home')] public function welcomePage(): Response { // Define the controller_name variable $controllerName = 'HomeController'; // Replace with the actual controller name return $this->render('home/index.html.twig', [ 'controller_name' => $controllerName, ]); } }
Editor is loading...