steampixel/simplePHPRouter

How to implement GET URL Query and 404 error page.

Closed this issue · 3 comments

hi, i like this code. i want help my question is
How to implement GET URL Query and 404 error page.

/search?q=query

Hi @shaziaijaz ,
please take a look at the index.php file. There you will find a 404-demo:

// Add a 404 not found route
Route::pathNotFound(function($path) {
  // Do not forget to send a status header back to the client
  // The router will not send any headers by default
  // So you will have the full flexibility to handle this case
  header('HTTP/1.0 404 Not Found');
  navi();
  echo 'Error 404 :-(<br>';
  echo 'The requested path "'.$path.'" was not found!';
});

And this could be your search boilerplate:

// Search example
Route::add('/search',function() {
  // Use the global $_GET PHP Array to access your q value.
  // Query the database
  // List the results
  // Do whatever you want
  echo 'You searched for '.$_GET['q'];
}, 'get');

thanks you