src/Controller/DashboardController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\DBAL\Connection// Ensure this is imported for the executeSql method
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class DashboardController extends AbstractController
  8. {
  9.     #[Route('/dashboard'name'app_dashboard')]
  10.     public function index(): Response
  11.     {
  12.         $user $this->getUser(); // Get the current authenticated user
  13.         return $this->render('dashboard/index.html.twig', [
  14.             'controller_name' => 'DashboardController',
  15.             'user' => $user// Pass the user to the template
  16.         ]);
  17.     }
  18.     #[Route('/'name'app_home')]
  19.     public function indexHome(): Response
  20.     {
  21.         $user $this->getUser(); // Get the current authenticated user
  22.         return $this->render('home/index.html.twig', [
  23.             'controller_name' => 'DashboardController',
  24.             'user' => $user// Pass the user to the template
  25.         ]);
  26.     }
  27.     #[Route('/execute-sql'name'execute_sql')]
  28.     public function executeSql(Connection $connection): Response
  29.     {
  30.         // Replace 'TEXT' with the desired type and adjust nullable or default as needed
  31.         $sql "ALTER TABLE variable ALTER COLUMN valeur_possible TYPE TEXT;";
  32.         try {
  33.             // Execute the SQL
  34.             $connection->executeStatement($sql);
  35.             return new Response('SQL executed successfully!');
  36.         } catch (\Exception $e) {
  37.             // Handle SQL errors gracefully
  38.             return new Response('Error executing SQL: ' $e->getMessage(), 500);
  39.         }
  40.     }
  41. }