schoenbeck / phprouter
This package is abandoned and no longer maintained.
No replacement package was suggested.
Router for php
1.1.1
2020-07-31 11:20 UTC
Requires
- symfony/yaml: ^5.1
This package is auto-updated.
Last update: 2022-03-29 01:00:59 UTC
README
Easy to install with composer
$ composer require schoenbeck/phprouter
Usage
Friendly URL
Create a simple .htaccess file on your root directory if you're using Apache with mod_rewrite enabled.
Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ /index.php [L,QSA]
This is a simple example of routers in action
<?php include_once "../vendor/autoload.php"; use SCHOENBECK\Router\GlobalsRequest; use SCHOENBECK\Router\Router; $request = new GlobalsRequest(); $router = new Router($request); $router->addRoute("/","IndexController::indexAction"); echo $router->resolveRoute();
Load routers from a yaml
file
We can define in a yaml
file all the routes of our application. This facilitates our life when we need to migrate, modify, or later add new routes.
The route definition should follow the example below:
base_path: /blog routes: index: [/index, IndexController::indexAction] contact: [/contact, ContactController::indexAction] about: [/about, AboutController::indexAction]
Now we only have to add the routes file name:
$router->addRoutesFromFile("routes.yml");
License
MIT Licensed, http://www.opensource.org/licenses/MIT