‫All right guys.
‫So in the last video we left off with an error.
‫It says class router not found.
‫So the auto loader isn't working because in Composer.json we specified the framework namespace and we
‫haven't created that yet.
‫So basically what we want to do is go into our framework.
‫And anything that's in here is going to be categorized under the framework namespace.
‫So you can think of it as like a, like a category.
‫If you're if you have a list of movies, you're going to have horror comedy.
‫ET cetera.
‫So you can kind of think of it like that.
‫So anything in here is going to be namespace to framework.
‫And we do that by going into the file and up at the top here we'll say namespace.
‫Framework.
‫Okay.
‫So this is the database class which is now going to be in that namespace.
‫Same thing with the router.
‫So we can close that.
‫Go to the router.
‫Go up to the very top here and say namespace.
‫Framework.
‫All right.
‫We'll save that now whenever we use the for instance, whenever we use the router we need to specify
‫that namespace.
‫And this makes it this avoids conflict.
‫So you could have a router somewhere else that is part of a different namespace.
‫I mean there's probably not too many instances where you're going to do that, but there might be something
‫else where you have multiple classes that have the same name.
‫You might be using third party libraries and frameworks, and it just avoids conflict.
‫So it's good to use namespaces.
‫Now to use the framework namespace here.
‫There's a couple of ways I could do it.
‫I'll show you kind of the crappy way first, which would be where we're actually instantiating the router.
‫I could say framework and then slash router back slash router.
‫Now notice it says class router not found.
‫Watch when I save this and reload.
‫Now it says class database not found.
‫So we do still have an error.
‫But this one is cleared up.
‫Now a better way to do this.
‫Just so you don't have to use this before everything.
‫You could actually just go to the top and just say I'm going to use Framework slash.
‫And you can see with VS code it even pops up database or router.
‫It knows that those are in our in this namespace.
‫So we'll say router.
‫And this is the type of thing you see in Laravel all the time.
‫There's all types of namespaces.
‫Some of them are named really weird.
‫So let's save that reload.
‫We still get just the database error.
‫So now let's go to where we're using our database which would be in our controllers.
‫So in app controllers.
‫And let's go to home.
‫So right here again we could put framework here.
‫But I'm going to go up here and say use.
‫Framework slash database.
‫And then we're going to put that.
‫In where else?
‫We're using it here as well.
‫And that's index.
‫And then in show.
‫Okay.
‫Let's reload.
‫Now, one other thing that we need to address is now it says class framework PDO not found.
‫So when we instantiated PDO in our database class which is right here, it's looking in the framework
‫namespace which obviously it doesn't exist in.
‫So for this to to work and not try to look in the framework namespace at the top here we can just say.
‫Use PDO.
‫Save that reload.
‫And there we go.
‫We're back.
‫And we should be able to go to like the show page and all that stuff.
‫So now our application is a little bit more verbose.
‫It's a little bit more professional.
‫We have our files are more categorized.
‫Not to mention we're now using an auto loader.
‫So anything that we put in our framework folder any classes we don't have to require we can also use
‫subdirectories.
‫So I could put a subdirectory in framework.
‫And it would work if I didn't use the PSR for auto loader and we stuck with this, I wouldn't be able
‫to do that and I wouldn't be able to use namespaces.
‫All right.
‫So I think we're we're heading in the right direction.
‫So in the next video we're going to start to refactor our controllers because we want to be able to
‫have instead of just whole files for a controller like show PHP, for example, we want to have a single
‫file that represents all of the listings controllers.
‫So we'll have controller methods like show and index create.
‫So these will be methods in a class rather than their own files.
‫So we'll work on that next.