Search code examples
phpfat-free-framework

Custom routing doesn't work correctly [F3]


The custom route doesn't work correctly and always routes to user.htm

index.php

$routes = [
  "/" =>  "index.htm",
  "/user/id=@id" => "user.htm","/user/@id" => "user.htm",
];

foreach ($routes as $path => $file) {
  $f3->route("GET ".$path,
    function($f3){
      global $file,$path;
      echo View::instance()->render($file);
    }
  );
}

Solution

  • try this:

    $routes = [
      "/" => "index.htm",
      "/user/id=@id" => "user.htm",
      "/user/@id" => "user.htm",
    ];
    
    foreach ($routes as $path => $file)
    {
      $f3->route("GET " . $path,
        function ($f3) use ($file)
        {
          echo View::instance()->render($file);
        }
      );
    }