-
Notifications
You must be signed in to change notification settings - Fork 31
Core\Router
Routes are defined in app/routes.php
, which is then included and dispatched from the file app/bootstrap.php
by the method Core\Router::dispatch();
The basic router accepts uri
and a closure
:
Router::get('', function() {
Viewer::file('home.php');
});
Router::post('forms/signup', function() {
//
});
Router::put('', function() {
//
});
Router::delete('', function() {
//
});
HTTP methods supported at the moment is:
- GET
- POST
- PUT
- DELETE
They will be added from time to time.
Note: There are no need to put the root slash (/) or the beginning / because it can cause trouble in mostly Linux webservers.
You can also tell the router to accept parameters. This is also used for lazy routing.
Router::get('(:any)', function($match) {
Viewer::file($match);
});
The above code will route the uri /home to the file /home.php, while
Router::get('about/(:any)', function($match) {
Viewer::file('/anywhere/'.$match);
});
This will route /about/anything to the file /anywhere/anything.php
The router can also accept controllers, besides closure.
Router::get('demo', 'myclass::mymethod');
Or pass the parameter to the controller:
Router::get('demo/(:any)', 'myclass::mymethod');
Route groups are defined in the configuration file /config/routes.php:
return
[
'path' => DSS_PATH . 'routes' . '/',
'routes' =>
[
'web',
'api',
'auth',
'hello'
]
];
And is stored in the directory /routes
- web.php
- api.php
- auth.php
- hello.php