luckystar / php-router
A simple and fast PHP router
v1.4
2023-01-05 15:18 UTC
README
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"; });