Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sameer Borate:
How do MVC routers work
Jul 24, 2018 @ 14:21:08

In a quick post to his site Sameer Borate looks more in-depth at how MVC routers work to translate the incoming request and point it to the right code for handling.

A MVC Router class or a Dispatcher inspects the URL of an HTTP request and attempts to match individual URL components to a Controller and a method defined in that controller, passing along any arguments to the method defined.

He provides the code for a simple example, matching the path directly from $_SERVER['PATH_INFO'] to a key name in a set of routes. Routes are added to the list via an add_routes method and are only matched directly. This is the most basic version of a router with many other frameworks stacking features on top including wildcard matching, optional parameters and regular expression matching.

tagged: mvc router functionality introduction path match

Link: https://www.codediesel.com/php/how-do-mvc-routers-work/


Trending Topics: