Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
69% | Total: 158 | All time: 8,997 This week: 673 |
Version | License | PHP version | Categories | |||
routerlite 1.2.1 | MIT/X Consortium ... | 5.5 | HTTP, PHP 5, Tools, Design Patterns |
Description | Author | ||||||||
This class can route HTTP requests by URL pattern to callbacks. |
|
> This package deprecated and no more develop. See bit55/litero
instead (https://github.com/bit55/litero).
Extremely simple router for small web applications. Small footprint, no overhead.
Router class in this package can route HTTP requests by URL pattern to callbacks.
It can register URL patterns to match and associates callback functions to each pattern.
When the current request URL matches one of the patterns, the respective callback function is called to handle the request.
You may install this component via Composer:
composer require devgkz/routerlite
Or download this repository and include file Router.php directly and place in your application directory.
Your webserver must point to the index.php file for any URI entered. See .htaccess
for Apache and Nginx config in example
directory.
Get Instance of Router class.
$router = RouterLite\Router::getInstance();
Add your route rules. Routes may contents exact or wildcard-rules.
Windcards sample:
* /page/:any
- any characters, like /page/qwerty or /page/123
* /page/:num
- digits only, like /page/123
Route handler may be any callable (function name, closure) or string with controller class name and action method.
Router instantiate controller and execute action method automatically.
Note if you using Composer, add your controller classes to autoloading.
Add single rule with Closure handler:
$router->add('/', function () {
// Any output
// or yor template processing
echo 'Hello!';
});
Or/and define routes as array.
$routes = array(
'/sample' => 'SampleController@indexAction',
'/blog/:num/:any' => 'SampleController@viewPostAction',
'/blog/:any' => 'SampleController@viewAction'
);
$router->add($routes);
Start route processing.
$handler = $router->dispatch();
if ($handler) {
// Execute handler
$router->execute($handler, $router->vars);
} else {
// Show not found page
http_response_code(404);
echo '404 Not found';
}
Usage example see in example
folder.
Files (7) |
File | Role | Description | ||
---|---|---|---|---|
example (2 files) | ||||
src (1 file) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
nginx-host-sample.conf | Data | Nginx config file | ||
README.md | Doc. | Documentation |
Files (7) | / | example |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
User Ratings | User Comments (1) | ||||||||||||||||||||||||||||||||||
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.