2017 © Pedro Peláez
 

library diggy-router

Simple routing component for PHP

image

webcretaire/diggy-router

Simple routing component for PHP

  • Friday, July 6, 2018
  • by Webcretaire
  • Repository
  • 1 Watchers
  • 1 Stars
  • 130 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 19 Versions
  • 5 % Grown

The README.md

DiggyRouter

Latest Stable Version Total Downloads License Build Status, (*1)

Simple routing component for php, (*2)

Installation

Currently the only way of installing is via composer :, (*3)

composer require webcretaire/diggy-router

Basic Usage

First you have to register the routes you want to use in a YAML file with the following structure :, (*4)

routes:
  # First Route
  - uri: '/addressOfYourPage'
    controller: 'Name\Of\A\Class'
    action: 'nameOfTheFunctionToCall'
  # Second Route
  - uri: '/addressOfYourSecondPage'
    controller: 'Name\Of\A\Class'
    action: 'nameOfTheFunctionToCall'
  # ...

Note that the "action" parameter is optionnal, if it is not provided the router will try to call a "render()" function with no parameters, (*5)

Then create a new router :, (*6)

$router = new DiggyRouter\Router()

Load your routes into the router :, (*7)

$router->loadRoutes("path/to/your/routing.yml");

Use the router to call the correct function in the correct controller according to the requested URI :, (*8)

$router->handleRequest();

Advanced usage

By default the router tries to find a route that matches the requested URI which is stored in $_SERVER['REQUEST_URI'], but you can specify the URI to use by passing it to the function :, (*9)

$router->handleRequest($customURI);

DiggyRouter now supports multiple URIs for one route, you just have define the uri parameter of your route as an array :, (*10)

routes:
  - uri: 
      - '/firstPage'
      - '/secondPage'
    controller: 'Name\Of\A\Class'
    action: 'nameOfTheFunctionToCall'
  # ...

If you have complex URIs, you can specify an expression that the requested URI must match. The default delimiter is '~' but you can specify which one to use by doing :, (*11)

$router->setDelimiter('YourDelimiter');

If you have a lot of URIs, you can split your routes between one main routing file and as many secondary files as you want :, (*12)

# Main routing file
includes:
  - 'secondRoutingFile'
  - 'thirdRoutingFile'

routes:
  - uri: '/SomeAdditionnalRoutes'
    controller: 'Name\Of\A\Class'
  # ...
# Second routing file
routes:
  - uri: '/RoutesEverywhere'
    controller: 'Name\Of\A\Class'
  # ...

Examples

You can see a full example in this routing file, (*13)

The Versions

06/07 2018

dev-master

9999999-dev

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien EMMANUEL

06/07 2018

v1.5.0

1.5.0.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien EMMANUEL

03/09 2017

v1.4.0

1.4.0.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien EMMANUEL

08/08 2017

v1.3.3

1.3.3.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien EMMANUEL

08/08 2017

v1.3.2

1.3.2.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien EMMANUEL

08/08 2017

v1.3.1

1.3.1.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien EMMANUEL

08/08 2017

v1.3.0

1.3.0.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien EMMANUEL

02/08 2017

v1.2.3

1.2.3.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julien EMMANUEL

31/07 2017

v1.2.2

1.2.2.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

31/07 2017

v1.2.1

1.2.1.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

31/07 2017

v1.2.0

1.2.0.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

31/07 2017

v1.1.0

1.1.0.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

24/07 2017

v1.0.3

1.0.3.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

21/07 2017

v1.0.2

1.0.2.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

21/07 2017

v1.0.1

1.0.1.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

21/07 2017

v1.0.0

1.0.0.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

21/07 2017

v0.0.3

0.0.3.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

21/07 2017

v0.0.2

0.0.2.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL

21/07 2017

v0.0.1

0.0.1.0

Simple routing component for PHP

  Sources   Download

MIT

The Requires

 

by Julien EMMANUEL