Skip to content
HomeController.php 859 B
Newer Older
Адлан Шамавов's avatar
Адлан Шамавов committed
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class HomeController extends AbstractController
{
Адлан Шамавов's avatar
Адлан Шамавов committed
    #[Route('/search/{id}', name: 'home_search')]
    public function search(int $id): Response
Адлан Шамавов's avatar
Адлан Шамавов committed
    {
Адлан Шамавов's avatar
Адлан Шамавов committed
        $array = [
            ['id'=>10, 'name'=>'Jhon', 'age'=>23],
            ['id'=>32, 'name'=>'Alex', 'age'=>34],
            ['id'=>54, 'name'=>'Bob', 'age'=>45],
            ['id'=>6, 'name'=>'Mike', 'age'=>61],
        ];
        $rowId = array_search($id, array_column($array, 'id'));
        return $this->json($rowId);
Адлан Шамавов's avatar
Адлан Шамавов committed
    }

    #[Route('/', name: 'home')]
    public function home(): Response
    {
Адлан Шамавов's avatar
Адлан Шамавов committed
        return $this->redirectToRoute('home_search', [
            'id' => 32
        ]);
Адлан Шамавов's avatar
Адлан Шамавов committed
    }
}