Routing - ace411/Bingo-Framework GitHub Wiki
#Routes
Routing makes accessing Controllers possible; URL path fragments are mapped to the appropriate Controller methods to achieve application functionality. The base Router class in the MVC application is at the heart of all URL-related operations and is, effectively, a conduit.
##Creating Routes
Creating routes can be done in the index.php file in the public directory. Pattern matching techniques are used to match the URL information entered by a user to the "routing table" contents. A simple route can be defined like this:
$router = new Core\Router;
$router->addRoute("sample", ["controller" => "Bingo", "action" => "sample"]);
The keys of the associative array are self-explanatory and further explain the MVC structure. Though it is possible to repeat the addRoute()
declaration as many times as you need to, it is a lot better to define a routing scheme that can be implemented by the core Router class. Something like the snippet shown below should suffice.
$router->addRoute("{controller}/{action}");
To create routes with regular expression constraints, you can specify the expressions to use in your route. Consider the code shown below:
$router->addRoute("{controller}/{action}/{id:\d+}");
The result is the addition of a route with an additional id
parameter similar to something like this:
<scheme>/<host>/<controller>/<action>/<integer>
or http://localhost:8080/home/index/12