https://github.com/gregdel/php-router
Simple RESTful php router (no longer maintained)
https://github.com/gregdel/php-router
Last synced: 8 months ago
JSON representation
Simple RESTful php router (no longer maintained)
- Host: GitHub
- URL: https://github.com/gregdel/php-router
- Owner: gregdel
- Created: 2012-09-25T07:36:29.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-09-25T12:41:45.000Z (over 13 years ago)
- Last Synced: 2025-04-08T02:37:48.392Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 97.7 KB
- Stars: 20
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# php-router
****
Simple RESTful php router inpired by Slim framework
# Files
* .htaccess - Redirect everything to the app
* input.php - The HTTP headers and start the app
* API/api.php - The API with all the routes
* API/router.php - Router class
* API/route.php - Route class
To add features to the app, you only have to edit the `api` file.
# Add a route
router = new router();
router->addRoute(@method, @pattern, [@optional_functions], @function);
router->run();
## Method
The method is a string.
It should be GET, POST, PUT, DELETE
## Pattern
You can do simple things like getting a page :
$router->addRoute('GET', '/', function() {
header('Location: index.html');
});
You can use arguments :
$router->addRoute('GET', '/info/:day/:month/:year', function($day,$month,$year) {
echo "Infos for $day/$month/$year";
});
## Optional functions
You can add optional function, to check authentication for exemple.
function hello() { echo "Hello "; }
function world() { echo "world "; }
$router->addRoute('GET', '/helloworld' , hello(), world(), function() {
echo "!";
});
# Main function
You can do basic stuff as showned before. You can also use objects:
$router->addRoute('GET', '/datas', function() use ($db, $message, $session) {
$entries = $db->lastestEntries($session->getUserid());
$message->setData($entries);
$message->send();
});