<?php
namespace App\Controller;
use App\Service\ExportAndImportTable;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
/**
* @Route("/home", name="home")
*/
public function index(): Response
{//vvv
$breadcrumbs = $this->breadcrumbs($separator = ' » ', $home = 'Accueil');
return $this->render('home/index.html.twig',[
'page_title' => 'Page d\'accueil'
]);
}
/**
* This function will take $_SERVER['REQUEST_URI'] and build a breadcrumb based on the user's current path
*
* @param str $separator Breadcumb separator
* @param str $home Home text
*
* @return string Breadcumb HTML
*/
public function breadcrumbs($separator = ' » ', $home = 'Accueil')
{
// This gets the REQUEST_URI (/path/to/file.php), splits the string (using '/') into an array, and then filters out any empty values
$path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
// This will build our "base URL" ... Also accounts for HTTPS :)
$base = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
// Initialize a temporary array with our breadcrumbs. (starting with our home page, which I'm assuming will be the base URL)
$breadcrumbs = ["<a href=\"$base\">$home</a>"];
// Find out the index for the last value in our path array
$last = $path[count($path) - 1];
// Build the rest of the breadcrumbs
foreach ($path AS $x => $crumb) {
// Our "title" is the text that will be displayed (strip out .php and turn '_' into a space)
$title = ucwords(str_replace(['.php', '_'], ['', ' '], $crumb));
// If we are not on the last index, then display an <a> tag
if ($x != $last)
$breadcrumbs[] = "<a href=\"$base$crumb\">$title</a>";
// Otherwise, just display the title (minus)
else
$breadcrumbs[] = $title;
}
// Build our temporary array (pieces of bread) into one big string :)
// return implode($separator, $breadcrumbs);
return $breadcrumbs;
}
/**
* @Route("/home/portail-administration/Gestion-des-Bases-de-donnees/table/export/{table_name}", name="app_portail_administration-bdd_table-export")
*/
public function tableExportFile($table_name, Request $request, ExportAndImportTable $ExportAndImportTable): Response
{
return $ExportAndImportTable->ExportTable($table_name);;
}
}