// GET route to a controller method
$router->get('/about', '\Wojo\Controller\Front\PageController@about');
// GET route with a closure
$router->get('/hello', function () {
echo 'Hello, World!';
});
// POST route
$router->post('/contact', '\Wojo\Controller\Front\PageController@contactPost');
// Match any HTTP method
$router->all('/api/ping', function () {
echo json_encode(['status' => 'ok']);
});
Framework Docs
Routing
Routing
The Router class maps URL patterns to controller methods or closures. Routes are registered in routes/front.php using a simple, expressive API that supports all HTTP methods, grouped prefixes, middleware, and URL parameters.
Namespace: Wojo\Core\Router
Basic Route Registration
HTTP Method Shortcuts
| Method | Signature | Description |
|---|---|---|
| get() | get(string $pattern, callable|string $handler): self |
Register a GET route |
| post() | post(string $pattern, callable|string $handler): self |
Register a POST route |
| put() | put(string $pattern, callable|string $handler): self |
Register a PUT route |
| delete() | delete(string $pattern, callable|string $handler): self |
Register a DELETE route |
| patch() | patch(string $pattern, callable|string $handler): self |
Register a PATCH route |
| options() | options(string $pattern, callable|string $handler): self |
Register an OPTIONS route |
| match() | match(string $methods, string $pattern, callable|string $handler): self |
Register one or more pipe-separated methods |
| all() | all(string $pattern, callable|string $handler): self |
Register for all HTTP methods |
Grouped Routes with mount()
Group routes under a shared URL prefix. The prefix is prepended to every route registered inside the callback.
$router->mount('/docs', function () use ($router) {
$router->get('/introduction', '\Wojo\Controller\Front\DocumentationController@introduction');
$router->get('/routing', '\Wojo\Controller\Front\DocumentationController@routing');
$router->get('/database', '\Wojo\Controller\Front\DocumentationController@database');
// → registers /docs/introduction, /docs/routing, /docs/database
});
URL Parameters
Use {param} syntax to capture named segments. The Router auto-resolves typed parameters via the App container.
$router->get('/posts/{id}', function (int $id) {
// $id is automatically cast to int
echo "Post $id";
});
$router->get('/users/{username}', '\Wojo\Controller\Front\UserController@profile');
| Token | Pattern | Matches |
|---|---|---|
| :any | .* |
Any characters including / |
| :id | [1-9][0-9]* |
Positive integer (no leading zero) |
| :s | [a-z0-9\-]+ |
Slug (letters, digits, dash) |
| :d | \d+ |
One or more digits |
Middleware with before()
Attach middleware to all routes or to a specific mount group. Return false from the middleware to halt the chain.
// Global before-middleware for all GET requests
$router->before('GET', '/admin/.*', function () {
if (!Session::isExists('admin_id')) {
Url::redirect(SITEURL . 'login/');
return false;
}
});
// Per-mount middleware (fluent)
$router->mount('/api', function () use ($router) {
$router->get('/users', '\Wojo\Controller\Api\UserController@index');
})->before(function () {
// runs before every /api/* route
});