1. Go to this page and download the library: Download the-systems/route library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
function pages() {
echo 'Page Content';
}
$route->get('/', 'pages');
class home
{
function pages() {
echo 'Home page Content';
}
}
$route->get('/', ['home', 'pages']);
// OR
$home = new home;
$route->get('/', [$home, 'pages']);
// OR
$route->get('/', 'home@pages');
$route->any('/', function() {
// Any method requests
});
$route->get('/', function() {
// Only GET requests
});
$route->post('/', function() {
// Only POST requests
});
$route->put('/', function() {
// Only PUT requests
});
$route->patch('/', function() {
// Only PATCH requests
});
$route->delete('/', function() {
// Only DELETE requests
});
// You can use multiple methods. Just add _ between method names
$route->get_post('/', function() {
// Only GET and POST requests
});
$route->get(['/', 'index', 'home'], function() {
// Will match 3 page in one
});
// This example will match any page name
$route->get('/?', function($page) {
echo "you are in $page";
});
// This example will match anything after post/ - limited to 1 argument
$route->get('/post/?', function($id) {
// Will match anything like post/hello or post/5 ...
// But not match /post/5/title
echo "post id $id";
});
// more than parameters
$route->get('/post/?/?', function($id, $title) {
echo "post id $id and title $title";
});
// This example will match anything after blog/ - unlimited arguments
$route->get('/blog/*', function() {
// [$this] instanceof ArrayObject so you can get all args by getArrayCopy()
pre($this->getArrayCopy());
pre($this[1]);
pre($this[2]);
});
$route->get('/{username}/{page}', function($username, $page) {
echo "Username $username and Page $page <br>";
// OR
echo "Username {$this['username']} and Page {$this['page']}";
});
// Validate args by regular expressions uses :(your pattern here)
$route->get('/{username}:([0-9a-z_.-]+)/post/{id}:([0-9]+)',
function($username, $id)
{
echo "author $username post id $id";
});
// You can add named regex pattern in routes
$route->addPattern([
'username' => '/([0-9a-z_.-]+)',
'id' => '/([0-9]+)'
]);
// Now you can use named regex
$route->get('/{username}:username/post/{id}:id', function($username, $id) {
echo "author $username post id $id";
});
$route->group('/{lang}?:isoCode2', function($lang)
{
$default = $lang;
if (!in_array($lang, ['ar', 'en'])) {
$default = 'en';
}
$this->get('/', function($lang) use($default) {
echo "lang in request is $lang<br>";
echo "
$route->use(function (){
$req = app('request');
pre('Do something before all routes', 3);
});
$route->before('/', function (){
pre('Do something before all routes', 4);
});
$route->before('/*!admin', function (){
pre('Do something before all routes except admin', 4);
});
$route->before('/admin|home', function (){
pre('Do something before admin and home only ', 4);
});
$route->after('/admin|home', function (){
pre('Do something after admin and home only ', 4);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.