src/Controller/HomeController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\ExportAndImportTable;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class HomeController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/home", name="home")
  12.      */
  13.     public function index(): Response
  14.     {//vvv
  15.         $breadcrumbs = $this->breadcrumbs($separator = ' &raquo; ', $home = 'Accueil');
  16.         return $this->render('home/index.html.twig',[
  17.             'page_title' => 'Page d\'accueil'
  18.         ]);
  19.     }
  20.     /**
  21.      * This function will take $_SERVER['REQUEST_URI'] and build a breadcrumb based on the user's current path
  22.      * 
  23.      * @param str $separator Breadcumb separator
  24.      * @param str $home Home text
  25.      * 
  26.      * @return string Breadcumb HTML
  27.      */
  28.     public function breadcrumbs($separator = ' &raquo; ', $home = 'Accueil')
  29.     {
  30.         // This gets the REQUEST_URI (/path/to/file.php), splits the string (using '/') into an array, and then filters out any empty values
  31.         $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
  32.         // This will build our "base URL" ... Also accounts for HTTPS :)
  33.         $base = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
  34.         // Initialize a temporary array with our breadcrumbs. (starting with our home page, which I'm assuming will be the base URL)
  35.         $breadcrumbs = ["<a href=\"$base\">$home</a>"];
  36.         // Find out the index for the last value in our path array
  37.         $last = $path[count($path) - 1];
  38.         // Build the rest of the breadcrumbs
  39.         foreach ($path AS $x => $crumb) {
  40.             // Our "title" is the text that will be displayed (strip out .php and turn '_' into a space)
  41.             $title = ucwords(str_replace(['.php', '_'], ['', ' '], $crumb));
  42.             // If we are not on the last index, then display an <a> tag
  43.             if ($x != $last)
  44.                 $breadcrumbs[] = "<a href=\"$base$crumb\">$title</a>";
  45.             // Otherwise, just display the title (minus)
  46.             else
  47.                 $breadcrumbs[] = $title;
  48.         }
  49.         // Build our temporary array (pieces of bread) into one big string :)
  50.         // return implode($separator, $breadcrumbs);
  51.         return  $breadcrumbs;
  52.     }
  53.        /**
  54.      * @Route("/home/portail-administration/Gestion-des-Bases-de-donnees/table/export/{table_name}", name="app_portail_administration-bdd_table-export")
  55.      */
  56.      
  57.      public function tableExportFile($table_name, Request $request, ExportAndImportTable $ExportAndImportTable): Response
  58.      {
  59.         
  60.          return $ExportAndImportTable->ExportTable($table_name);;  
  61.  
  62.      }
  63. }