‫All right.
‫So now we're going to clean up our router a little bit.
‫In this video.
‫We're going to basically clean up this index.php and move these two separate files.
‫There's one thing that I want to fix real quick.
‫So in the logo here if I click it it's going to index HTML which obviously doesn't exist.
‫So let's fix that real quick by going to partials and then to the nav bar.
‫And right here where it says index HTML.
‫Let's get rid of that and just put slash.
‫So that way if we go to another page we can just click on the logo.
‫It takes us back home.
‫All right.
‫So I'm going to separate these into two separate files.
‫One is going to be for our routes.
‫One will be for the router logic.
‫So for now let's create a file in the in the root here called routes dot PHP.
‫And we want this to hold our roots now instead of.
‫Putting it into a variable in that file.
‫What I'm going to do is, is just take this array.
‫I'll cut that out and I'm going to just return it.
‫Actually we need our PHP tag.
‫And then we'll say return and then that array of routes.
‫Okay.
‫So we can close that up.
‫So any time we want to create a new route we can just go to that file.
‫Now let's get rid of that.
‫And let's work on putting this in a separate file.
‫And like I said we will have a router class with methods.
‫But for now in the route here I'm just going to create a router dot PHP file.
‫And we're basically just going to grab this.
‫We'll keep the Uri in the in the index.
‫I just want to take this router logic here.
‫Cut that put that into.
‫The router dot PHP.
‫Now this Uri variable is available because we're going to require this right under where we define the
‫Uri here.
‫You could define this in the router file.
‫But we're going to need this later on.
‫So let's just use it here and then require let's say base path.
‫And we want to require the router dot PHP.
‫Now in the router we need access to the routes which right now are in a separate file.
‫So right above that if statement let's require.
‫Base path and we want to require routes dot PHP.
‫All right, so let's just make sure everything is saved and reload.
‫Undefined variable routes.
‫That's because we want to set.
‫Roots equal to that require.
‫And there we go.
‫Okay, you can make sure the roots work if you want.
‫Now, one other thing I want to do is if we go to something that doesn't exist and it loads the 404.
‫Right.
‫I'm going to just open up the network tab for a second here.
‫So if we go to our dev tools and we go to network.
‫Just pull this up and I'm just going to reload this.
‫And I want you to look down here at the pages and right here, this is the page being loaded, right.
‫This is the main document and it has a status of 200, which means okay.
‫And since this is a 404 we should really change that status.
‫In PHP there's a function we can use called Http response code.
‫And we can change that to whatever response code we want.
‫So down here where we have the else when we're loading the 404, let's go right before it.
‫And let's say Http underscore response code.
‫And we're going to pass in 404.
‫Okay.
‫And then when I do that, and if I come back to this page, I reload.
‫Now you'll see that it's actually getting a 404 response, which is the proper response.
‫All right.
‫So I just wanted to add that in there.
‫Now in the next video we're going to ramp it up a bit.
‫And we want to be able to not only map a URL to a controller like we're doing here, but we also want
‫to be able to specify an Http method.
‫Is it a Get request, a Post request, put delete.
‫So we want to stick to kind of a RESTful architecture.
‫All right.
‫So we'll be upgrading our router in the next video.