Routes are declared through the interfaces provided by the Route class. HotMelt will automatically load Site/routes.php, so you should use that file to declare routes.
<?php
\HotMelt\Route::add('/^\/$/', 'MySite\\Blog::index', 'Index.html');
\HotMelt\Route::add('/^new-post$/', 'MySite\\Blog::newPost', 'NewPostEditor.html');
// This is the target of the post editor form in NewPostEditor.html.
// It only accepts POST requests.
\HotMelt\Route::add('/^new-post$/', 'MySite\\Blog::newPost', 'NewPostEditor.html', 'POST');
Route::add() takes these arguments:
- A regular expression to match against the request URI.
- A callable identifying the action.
- The name of a view, which can be either a class name or the name of a [Twig][twig] template in
Site/Templates(optional). - A string or an array of strings identifying the valid HTTP methods for this route (optional).
- An array of options (optional). This is typically used for per-route configuration of middleware options, such as
Middleware\BasicAccessAuthentication.
Pass null for the $action parameter and HotMelt will use a default action implementation (as returned by HotMelt\Action::defaultAction()). This can be useful if you want to render a template for a route that does not require any action level processing.
Routes are evaluated in the order they have been declared in. If you want to define the same options for multiple routes, you can bracket these in calls to Route::pushDefaultOptions() and Route::popDefaultOptions().