2017 © Pedro Peláez
 

library router

A really simple dependency-free PHP router

image

rgehan/router

A really simple dependency-free PHP router

  • Wednesday, April 19, 2017
  • by rgehan
  • Repository
  • 0 Watchers
  • 2 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

rgehan/router-php

This is a really simple router, it has no external dependency. It allows you to define routes, for specific verbs, and map them to a method in a controller class., (*1)

I loosely imitates Laravel router., (*2)

Installation

Simple require it with Composer, (*3)

composer require rgehan/router

Usage

This code should reside in a PHP file where all requests are redirected to (with an .htaccess file for example)., (*4)

<?php

// Requires the Composer autoloader, allowing us to use external modules
require_once(__DIR__ . "/../vendor/autoload.php");

use rgehan\RouterPHP\Router;

// Sets the namespace in which the Router will look for controllers
Router::setControllerNamespace('\\rgehan\\myProject\\controllers\\');

// Sets the variables that will be passed to all controllers methods
Router::setRoutesGlobalParameters(['global variable 1', 123, [1, 2, 3]]);

// Defines the routes
Router::get('/', 'HomeController@index');
Router::get('/home', 'HomeController@index');
Router::get('/articles', 'ArticlesController@index');
Router::get('/article', 'ArticlesController@get');

Router::post('/search/name', 'ArticlesController@search');

Router::delete('/article', 'ArticlesController@delete');

Router::update('/article', 'ArticlesController@delete');

// Dispatch the current request to the correct controller/method
Router::dispatch();

Current limitation

Unlike many routers, this one doesn't allow you to define dynamic parameters in the url (such as /article/{id} for example). You still have to rely on good'ol $_GET, or $_POST to get your data., (*5)

After all, it's just a router, not a full framework :), (*6)

The Versions

19/04 2017

dev-master

9999999-dev

A really simple dependency-free PHP router

  Sources   Download

MIT

by Renan GEHAN

19/04 2017

1.0.4

1.0.4.0

A really simple dependency-free PHP router

  Sources   Download

MIT

by Renan GEHAN

19/04 2017

1.0.3

1.0.3.0

A really simple dependency-free PHP router

  Sources   Download

MIT

by Renan GEHAN

18/04 2017

1.0.2

1.0.2.0

A really simple dependency-free PHP router

  Sources   Download

MIT

by Renan GEHAN

18/04 2017

1.0.1

1.0.1.0

A really simple dependency-free PHP router

  Sources   Download

MIT

by Renan GEHAN

18/04 2017

1.0

1.0.0.0

A really simple dependency-free PHP router

  Sources   Download

MIT

by Renan GEHAN