edom / simple-router-php
Simple Router in PHP to use in small projects
dev-master
2020-04-23 21:40 UTC
This package is auto-updated.
Last update: 2024-12-24 15:23:24 UTC
README
.htaccess
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]
Start with package
require_once "../vendor/autoload.php"; use EDOM\SimpleRouterPHP\Router; $router = new Router("EDOM\\");
Router receive as parameter the namespace where you manage your controllers
GET
$router->get('/', function () { echo "get"; }); $router->get('/users/[i:id]', 'UsersController@show');
POST
$router->post('/', function () { echo "post"; }); $router->post('/users/[i:id]', 'UsersController@store');
PUT
$router->put('/', function () { echo "put"; }); $router->put('/users/[i:id]', 'UsersController@update');
DELETE
$router->delete('/', function () { echo "delete"; }); $router->delete('/users/[i:id]', 'UsersController@delete');
The structure to pass a controller is Class@method
Finally call this method
$router->match();