I am trying to learn a PHP framework. But I'm having some difficulties understanding some of the concepts of routing.
I've chosen to use Flight. Their homepage shows:
require 'flight/Flight.php';
Flight::route('/', function(){
echo 'hello world!';
});
Flight::start();
And I don't understand what they're using Flight::route...
for. What am I missing? This question isn't even related to Flight. It's related to just routing in general.
What seems to be happening in your file (I'm not familiar with Flight)
the
require 'flight/Flight.php';
is more than likely defining a class for all the routing.Then
Flight::route();
Is simply using theroute()
method from the classFlight
without an instance of the class.What happens here is when a route is matched (by matched means the URI of the user matches the URI on your route, in this case
www.yourdomain.com/
will match the'/'
route) And then the code inside thefunction()
callback gets executed.If you add another route
When the user visits
www.yourdomain.com/about
He will get whats inside that route.