Our framework is technically all ready for us to start building on top. However, we don't have enough support to match and handle complex routes. Since most applications will need this, let's quickly add it.
For example, in the index.php
file, we'll want to be able to define a route for a user profile. This route might be /user/:username
. In this case, :username
will be a variable that we can then access. So, if you went to the URL /user/tim
, you could access the username tim
by using Bones
to grab that section of the URL, and return its value.
Let's start by adding another variable and another call in our __construct
function to our lib/bones.php
file:
public $content = ''; public $vars = array(); public $route_segments = array(); public $route_variables = array(); public function __construct() { $this->route = $this->get_route(); $this->route_segments = explode('/', trim($this->route, '/')); $this->method = $this...