<?php
namespace App\Controller;
use Doctrine\DBAL\Connection; // Ensure this is imported for the executeSql method
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractController
{
#[Route('/dashboard', name: 'app_dashboard')]
public function index(): Response
{
$user = $this->getUser(); // Get the current authenticated user
return $this->render('dashboard/index.html.twig', [
'controller_name' => 'DashboardController',
'user' => $user, // Pass the user to the template
]);
}
#[Route('/', name: 'app_home')]
public function indexHome(): Response
{
$user = $this->getUser(); // Get the current authenticated user
return $this->render('home/index.html.twig', [
'controller_name' => 'DashboardController',
'user' => $user, // Pass the user to the template
]);
}
#[Route('/execute-sql', name: 'execute_sql')]
public function executeSql(Connection $connection): Response
{
// Replace 'TEXT' with the desired type and adjust nullable or default as needed
$sql = "ALTER TABLE variable ALTER COLUMN valeur_possible TYPE TEXT;";
try {
// Execute the SQL
$connection->executeStatement($sql);
return new Response('SQL executed successfully!');
} catch (\Exception $e) {
// Handle SQL errors gracefully
return new Response('Error executing SQL: ' . $e->getMessage(), 500);
}
}
}