Skip to content

HasanKaya53/php-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Router

simple and fast php page router.

#How Install

 composer require luckystar/php-router

Plase add .htacces file:

Features

  • GET/POST Methods
  • Simple To Use
  • Easily import php or html files
  • You cant use parameters. :(

upcoming features

  • Add Parameters.
  • Add Middleware

Usage/Examples

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Set Theme folder

LuckyStar\PhpRouter\BHRouter::$themeFolder = "src/themes/";

Calling php when the index request comes

LuckyStar\PhpRouter\BHRouter::get("/", 'index.php');

Calling php when the about request comes

LuckyStar\PhpRouter\BHRouter::get("/about", 'about-page.php');

Calling function when the index request comes

 LuckyStar\PhpRouter\BHRouter::post("/", function(){
    echo "test";
});

pass variables

$pages = ['index','header','footer'];
LuckyStar\PhpRouter\BHRouter::get("/", 'index.php', $pages);

Get URL Parameters

LuckyStar\PhpRouter\BHRouter::get('/bloglar/tes/{name}/{surname}', 'bloglar.php');

OR

LuckyStar\PhpRouter\BHRouter::get('/bloglar/tes/{name}/{surname}', function(){
    echo $_GET['name'];
    echo $_GET['surname'];
});

404 pages usage: (should be added to the end of the page. )

LuckyStar\PhpRouter\BHRouter::noOne("/404", function(){
    echo "there is no such page";
});