\Router

Router class

Summary

Methods
Properties
Constants
__construct()
add()
get()
post()
patch()
delete()
addWithMethod()
setNotFound()
dispatch()
redirect()
cache()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(string  $uri = '') 

Constructor

Parameters

string $uri

add()

add(string  $url, callable  $action) 

add route

Parameters

string $url
callable $action

get()

get(string  $url, callable  $action) 

Add get route

Parameters

string $url
callable $action

post()

post(string  $url, callable  $action) 

Add post route

Parameters

string $url
callable $action

patch()

patch(string  $url, callable  $action) 

Add patch route

Parameters

string $url
callable $action

delete()

delete(string  $url, callable  $action) 

Add delete route

Parameters

string $url
callable $action

addWithMethod()

addWithMethod(string  $method, string  $url, callable  $action) 

add a route with a method

$url:

  • /test
  • /test/* matches /test, /test/truc, /test/b/aaaa/ggg, ...
  • /test/:id matches /test/a, /test/1, /test/test, /test/me

Parameters

string $method
string $url
callable $action

setNotFound()

setNotFound(callable  $action) 

Add callback for 404 cases

Parameters

callable $action

dispatch()

dispatch() 

Dispatch routes

redirect()

redirect(string  $page, boolean  $perm = false) 

Redirect

Parameters

string $page

Route to redirect to

boolean $perm

If the redirection is permanent (alias SEO friendly)

cache()

cache(  $duration = false) 

Cache

Parameters

$duration

Duration in seconds or false to never cache