‫All right.
‫So you should have your project folder ready.
‫You should have it running in your browser.
‫And right now you just see hello world.
‫So our project our application is going to have a controller view structure.
‫So basically we're going to have controllers for each route.
‫So for instance if we go to the home page we'll have a home controller.
‫And any logic will go in there that we have.
‫And then it'll have a view which is basically just the, the HTML, the UI output.
‫Okay.
‫So what I want to do in this video is start on our home view.
‫So what we'll have is in our project folder we'll have a folder called views okay.
‫And for now let's create a file in here called home.
‫Now I like to prefix my views with dot view.
‫You don't have to do that.
‫But I just think that it's it's just easier.
‫And you can tell what's what.
‫So let's say home dot view dot PHP.
‫Now this is where I want the HTML to go for my home page.
‫Now you have the theme.
‫So I'm going to jump over to Sublime Text where I have my HTML, which is right here.
‫And for now, let's just grab everything that's here.
‫So I'm just going to copy every single thing.
‫I'm going to just do a select all, copy it, and then I'm going to paste it in here.
‫Right.
‫Because in a PHP file you can have straight HTML.
‫And we'll make this dynamic as we go.
‫So let's save that.
‫And then what we can do is in our index dot PHP file we can then bring that file in.
‫Now we did this a little bit with the database file in that section.
‫If you watch that section and we use require and that's what I want to use here.
‫But there's a couple ways that you can bring one PHP file into another.
‫And I just want you to understand the difference between those.
‫So you can use include which will include a file and if it fails, meaning that if that file isn't there
‫or whatever, it will throw a warning and continue to execute the script anyway.
‫Require will include a file, and if it fails, it'll throw a fatal error and stop executing the script.
‫Okay, include once you can use that as well, which will include a file only once.
‫If it has been already included, then it won't include it again and then require once will include
‫a file once.
‫If it hasn't already been included, it won't include it again, so you can use any of these for.
‫I usually use require.
‫So that's what I'm going to use.
‫But if again if you want to use something else that's fine.
‫So in our index.php let's go ahead and require and we want to bring in that home view.
‫So we want to go into the views directory so we can say dot slash and then views slash.
‫And then home view PHP.
‫And I'm just going to save that and reload the page.
‫And we're not going to see the CSS yet because we didn't bring that in.
‫Right.
‫So we just see the HTML.
‫Now this is something that I debated if I should do now or if I should do later.
‫But I don't want to have our, our public files like our, our index, PHP, our CSS, our any JavaScript
‫front, anything front end.
‫I don't want to just have in the root, I want to have that in a public folder.
‫So I want to make that public folder our document root okay.
‫So I'm going to show you how to do that.
‫And it's different depending on your system and how you have things set up.
‫So let's create a folder in the root called public right.
‫And then we're going to move the index.php into that public folder.
‫Now if I do that and I reload of course it's not going to work because it's looking for an index PHP
‫in the root.
‫So what I need to do is change my document root to that public folder.
‫And if you're using the PHP server, it's very simple.
‫All we have to do is stop the server.
‫And instead of just running, you know, php s localhost, then we can just run.
‫Let me just clear this up first so we can run php dash s.
‫Local host.
‫So we're going to run the same thing, but we're going to add on to it and we're going to say dash t
‫and then public.
‫What that's going to do is change the document route to public.
‫So now if I run that.
‫And now I come back over here and reload.
‫Okay, it's working, but we have another problem.
‫That is, we're requiring views from the public folder because it's just dot slash.
‫What we want to do is go up one level into that views folder now.
‫So I'm just going to add another dot.
‫Okay.
‫That'll go up into the views folder.
‫And if I reload now it works.
‫And of course we don't see our CSS because we haven't brought it over yet.
‫Now that's simple if you're using the PHP dev server, but I know some of you guys aren't.
‫Some of you are on windows.
‫So in the documents, the course docs for this particular section, we can come down here.
‫This is just the stuff that we already did.
‫So where it says changing the document route.
‫So for Apache users you need to update your document route in the dot conf file for your project.
‫And this is usually in the e.t.c. apache2 sites available.
‫And then your project.com.
‫So work dot conf.
‫Luckily, if you're using larrigan this is very easy.
‫You can just go to the task bar or whatever that's called down in the right on windows and the Larrigan
‫icon.
‫If you right click that there'll be an Apache option.
‫And then from there you can choose sites enabled.
‫And then you'll see a file that's called it's titled like this auto dot probably work opia whatever
‫you called your project conf and when you open it, you're going to see something like this.
‫The virtual host with your document root also has your server name and server alias, things like that.
‫But what you're going to want to do is simply add slash public at the end of the document root.
‫So right here you're going to want to just add slash public and it'll change the document root, just
‫like I did with my dev server okay.
‫Now you will have to restart Apache in order for that to take effect.
‫But once you do that you should see your site.
‫And then just make sure that you add that extra dot because now you're going up into the views folder.
‫All right.
‫So I'm going to close that.
‫Now the next step is to include our CSS and also our images.
‫So any public assets those are going to go in the public folder.
‫So I'm going to open up the theme.
‫So I have the theme files here.
‫And we're just going to take CSS.
‫Oops.
‫We just want CSS and images.
‫And you want to bring those into the public folder okay.
‫So now if we come over here and reload now the CSS works.
‫The images also shown in the hero.
‫Okay.
‫So obviously this is all just still just hard coded HTML.
‫But at least we have this showing up.
‫Now.
‫We're going to be requiring or including a lot of different files and doing it this way with doing it
‫relative and having to go up levels and down levels can be a little bit confusing.
‫So what I want to do is have a function that we can just wrap this in called base path.
‫And basically that will include the file without us having to add any of this we can just say views
‫and then home.
‫So in the root of the project we're going to have a file called helpers.
‫So helpers dot PHP.
‫And this is going to have obviously helper functions that we can use all around the site.
‫And this base path is one of those.
‫We'll be using it quite a bit.
‫So let's open up our PHP tags.
‫And I want to do I want to create this in kind of a professional type way.
‫So when we create functions or class methods etcetera, I'm going to have a doc block above it that
‫explains what it is and what params it takes and what it returns.
‫You don't have to do this, but I think it's good practice.
‫So if we do slash and then double asterisk, you'll see it actually adds the the end of the comment
‫on.
‫If I hit enter, it'll put an asterisk before where I'm about to type.
‫And I'm not sure honestly if that comes from the intellisense extension, I think it does.
‫Um, it's been a while since I actually checked this.
‫It might come from another one, though I'm not positive on that.
‫Just that functionality.
‫It might be this PHP doc blocker, so you might want to add that.
‫You might want to install that if you're using VS code.
‫If not then just type it out like this or don't use it at all.
‫So I'm going to say what it does.
‫This gets we'll say get the base path.
‫And then I'm going to add at params.
‫So what params does it take.
‫And the type which will be a string.
‫And it's going to take in a path.
‫Okay.
‫Then for the return value let's say at return it's going to return a string.
‫So let's come down and create the function.
‫We'll call it base path.
‫And I'm using camel Case for my my convention.
‫If you want you could do base underscore path.
‫But I prefer that.
‫And it's going to take in path.
‫And we'll set a default of just an empty string.
‫And then what I want to do is return the path that's that's passed in.
‫But I want the absolute path.
‫And we can do that by using double underscore dir double underscore.
‫And then we can concatenate onto that slash and then.
‫Whatever that path is.
‫All right, so that should work.
‫So what I'll do is, is now save that and let's go into our index.php which is in public.
‫So public index.php.
‫And we need to bring that helpers file in.
‫Now this is the only require that we can't use that base path because the base path function is in that
‫file.
‫So here we actually do have to do dot dot slash to go up out of public and then into helpers.
‫But now for our views we can now require.
‫Base path.
‫We can pass in.
‫The view like that.
‫Save and let's reload.
‫And we should still see our page here.
‫All right.
‫So that's pretty much all I wanted to do in this particular video.
‫I think we did quite a bit.
‫We set our our document route to public.
‫So all CSS images, front end JavaScript.
‫Excuse me.
‫That stuff will all go in here.
‫We have our views folder.
‫We have our home view which right now is just all HTML.
‫It even has the head body tags.
‫We're going to get into all that.
‫We're going to get into partials because we want to separate.
‫We want to take out the head and put that in a file so we can include it in other files, things like
‫that.
‫All right.
‫So yeah, in the next video we'll start to look at partials.