Skip to content

FlorianH/Router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Warning: This code is very old and has not been maintained for a long time.
You probably do not want to use this anymore. Consider looking at https://github.com/auraphp/Aura.Router.

A simple url router

This file contains a small url router, which is intended to be used in very small projects, where no real MVC framework fits the needs of the project.

Comments

To create a route, you just have to call the “Router::add” function and provide the intended url and the name of the function which is supposed to be called if the route matches.

The function name can contain a regular expression. Every matching argument, that can be extracted will be stored in the $args array.

Every function, that is supposed to be the endpoint of an url has to accept a single variable, which will contain the array of extracted arguments.

If you want to use class methods as your endpoints, just add the class’s name in front of the method’s name and add a dot after the class’s name.

For the bar method of this class:

class Foo {
  function bar($args) {...}
}

the endpoint has to be “Foo.bar”. See example usage in the example file (index.php).

The Router has only static methods, because that makes the api super nice (at least IMHO).

Usage:

require_once('Router.php');
Router::add('/example', 'example_function');
function example_function($args) {
  echo "Hello!<br />";
  print_r($args);
}
Router::run()

About

A small url router, which is intended to be used in very small projects, where no "real" MVC framework fits the needs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages