 Hey everybody this is Brian. Welcome to the third ye2 tutorial. That just sounds weird saying the ye2 So we're just gonna say ye tutorials because it just sounds better. Alright, so last video We actually made our database now this video We're gonna actually build the site and make some models to go with that database So first thing we want to do is we need to set up our site when we've done this before But I kind of want to do it again. Just so you can see the whole process here I'll bring a command line Make sure I'm in the right directory here. All right, good And then I'm you know if you remember from our previous conversation if I do PHP composer par I get an error I just do composer and then whatever this string is here. So let's Bring this back up And if you're curious, which one works type composer and hit enter and if you get this Then you follow the installation correctly. Otherwise, you may need you may need to actually do the PHP Composer dot phar So I'm just going to do composer Whoops, somehow I opened another window here Followed by all that gobbly-gook. Now what this really does is it tells composer to require that That being the asset plugin if you don't include that bad things will happen Hmm Did I misspell? Oh, yeah lobel Global and composer will do its magic and it'll update and make sure you're all up to date and everything's working The only bad part about composer really is if if somebody Modifies their files and it's not backwards compatible and you update. Well, then you just broke your code So now we're going to actually Create a project here Now we should note that you want to do this command in the directory you want your website So I'm going to do a print working directory and you can see I'm in var Html. That's my web root yours may be different depending on your installation. Oops. I don't want advanced. What was I thinking? Let's not do that bad things will happen. We want the basic site There we go. All right now We're going to dissect this command a little bit here So if you can follow my little cursor on the screen where it says composer, that's the command we're calling We're calling the composer file We're telling it to create a project using the esoft e2 at basic meaning This is going to be a basic application and then the name of this basic and then it's going to be using 2.0 point 6 Well, we want to rename this bad boy. We don't want basic So we want pet shop Was it pet shop or pet shore? pet store let's I don't remember Two days ago was just way too long ago for me. Let's do this. What was it to pet store? That's what it was Wow, glad we pet shop that would have been a disaster Can't even spell store that's kind of day I've had here my hands are like really cold and numb because I live in Michigan And it's like 10 degrees and we've just had like blizzard conditions for the last day and a half So I've been out snow blowing quite a bit Anyway, so we'll rename that to pet store and when we hit enter It's going to actually go out. It's going to download the e2 basic application from composer Um, and it's just going to start installing it And you can see how it starts downloading all the dependencies Those are all of the things that yee has used internally and without those it will just not function Just put it bluntly and you can see at the very trail end of this where it's actually done the change mode change mode change mode That's basically setting permissions. It's all really all it's doing here So there's my web route 127001. You can also do the local host And you should see pet store in here. You see I've got some other websites But we're just going to pet store and this is the structure of the website here You can see how there's this web folder. Well, this actually should be your web route I just have multiple in here So I wanted to show you that all of these folders should not be public facing. This is a big no no You want this to be your web route? And ta-da congratulations. Here is your beautiful website in all of its glory Yes, it created all this for you You can go to about and you can see it just says hey modify this file You can go to contact and it's got you know a nice little editor with a little verification code You can go to log in and it tells you right here. You can either do admin admin or demo demo We're just going to go admin admin No chrome do not remember my site. Please or my password Not effectively did nothing because we don't have any content. You can see how it says log out admin now um This gets into a little more of a complex topic where we call What is it a user identification or the current logged in user and what permissions you have which we'll get into in future tutorials But you can actually design your site so that One person's an administrator and one person's just a normal user and there's a whole big It's called rule base authentication and you can actually make different roles. It's really kind of crazy So what we want to really focus on here If you click on contact, you'll see how it says index php and then this question mark r equals This is called a route and this is used heavily in ye Basically everything goes through index dot eight uh that php And then index basically x is a bootstrap if you will It routes it to the correct controller and to the correct view You can tell the difference between the controller and the view by this percent 2f Which is actually html encoded for a slash sign So this is a little more illustrative here Site is the controller and contacts the view and we're going to actually bring that up in net beans here and Did you actually do that? No, you didn't Let's see if I can refresh this without closing net beans. There it is So here is our file structure here and you can see controllers. There's our site controller So if I just kind of move this down, you can see the controller site We're going to open this up And there's all the code in the controller now. Remember the controller controls the flow of traffic if you remember your mvc pattern here So all this does is it just says hey, what are we doing? And we're on the contact page so slash contact. So what we're looking for is something called action contact You see there's a couple. There's an action index action log in log out contact Well, as you can guess these are the actual pages There's an index. There's a log in a log out in a contact. So in contact Where we're at now You can see if I move this down you can see that beautiful little contact form that was generated for us And this is the the meat of mvc patterns if you will we have a model Remember a model is a representation of the data and we're saying it's a new contact form And then we're going to do something with that model Don't worry about you know the specifics of this just yet Just know that we're using a model or a representation of the data We're manipulating the data and then we're doing something with that data Whereas you have other pages Like about that just say return this render and then about now. What is this little guy? And you can see that it's got this render contact and then we're sending the model in there too Well, this is called a view. This is the actual presentation layer And let's break that out And break that out again and you see these are the actual pages under views and then each view Has a controller folder. So there's our site and you can see there's about So this is the actual template. So if we render about You can see this is the about page blah, blah, blah, and then it's got that This is the about page blah, blah, and then it's got the file So not a whole lot of magic going in there. It just takes a little getting used to We'll get into views and we'll talk about like breadcrumbs and things like that and how to structure your view and all that The other thing I kind of wanted to point out is that there is in the views a layouts folder And the main dot php This is the main Template that all the pages follow and that's where you get this You know these nice menus and everything And where is it? Yeah content. This is where the actual view is rendered inside of there Let me bring that up here Now if we go to models you can see there's already some models generated for us But none of them came from our database and that's what we're going to try to accomplish in this tutorial Is actually use what's called g to make some models So what are these? Contact form remember that was from that contact page extends model Well, if you remember from your php, this is inheritance So we have a model class that e is created somewhere and we're extending that and creating a contact form Remember the model is the representation of the data you hear me say that over and over and over again You really need to just nail that down because some people especially You know the know-it-alls of the world will say oh, well, we're going to use the model Which is the data? No, that's incorrect. The model is the representation of the data Um, so basically all this is is a class Remember a class from your you know previous tutorials is just a blueprint So really all we're saying is we have some data that we're going to call contract form or contact form And here's the blueprint that we're going to use and in there you can also include functions So it's actually pretty pretty slick the way mvc works So Now that we understand what a route is and now that we understand the you know basic structures of this We're going to go to a special route called g Is just g i i And tada here's g It says welcome to g a magical tool that can write code for you and I love g I'm a big fan of this now if you do this and you get a big fat error message or nothing comes up Then you're going to want to look in the config files and this may take me a minute here web And I haven't really messed around with this too much in ye2 here we go If ye environment dev meaning you're currently in development Then you know call the to debug module and then call the g module you want to make sure you're in development And you do that By basically being on your local host If you were to take and you see this little bar down here at the bottom If you were to take this and upload it to like a host gator or another web server something something other than 127001 You'll not see this in your in quote unquote production mode by automatically And you will not be able to work with g and you'll have to look up how to configure that to work you know across Cross the web boundaries if you will are in a different ip address So what is g why is important? What can we do? Well, it's a code generator You can make models meaning you can actually generate the representations of your database You can generate crud which stands for create read update and delete the basics of any web page And controllers you can actually create controllers and create forms modules You can create modules which is like think of a module as like a website within a website So let's say you build your pet store and you want an administrative back end that only you can get into and you control things Well, that would be a module And an extension generator Extensions. Well, let's just put it this way. Yee is vastly extendable And this will assist in creating those extensions. So we're going to start off with the basics We're going to go with the model generator Ooh This is a big boo boo. Look at this access denied for user root at localhost using password. No, what that means is we haven't set our database up yet So we're going to actually flip back in here. We're going to go to the db.php And you can see. Oh, yep. We never set up our database So we're using mysql. You may have to change that if you have something else And localhost db name Is ebasic too All right, so what we need to do here is we need to create a user and password combo In our mysql installation. We don't want to use root because root is well essentially god mode, right? So we're going to crack open mysql here and we're going to go to users and privileges And we're going to add an account and let's call this pet store why not Local connectivity. Well, basically we're going to use wildcards. So we're just going to say percent And the password we're just going to say super secure p-a-s-s-w-o-r-d Never do that in production. I'm just doing it for illustrative purposes If somebody really wants to hack my little pet store, let them Account limits max queries. We're going to just keep everything unlimited administrative roles Pretty much going to give this thing just god mode here um just because Yeah, just because in the real world you're going to want to lock this down You're going to want to determine what they can and cannot do and you're going to want to Research every one of these little things now. You should note that if you get a hosted service They're going to create an account for you They will give you a username and a password Or they'll have a nice GUI where you can create a username password and it does all of this in the background for you And we're not really going to mess around with that so we're just going to apply Notice how it says weak password. Thank you my sql for warning me about that Now pet store is in there Let's see if we can do this. So db name equal Pet store because we want to know which one we're going to We want the pet store username and the ultra scur password Let's save this and hopefully I don't look like a complete idiot here Ta-da, that's how you know you have access to your database because it just voila magically shows you this instead of an error message All right, you still have the same options. They're just off to the left now But we're going to actually use the model generator now if you mouse over the little underscore things It'll actually pop open this thing and you can actually put Prefixes and suffixes and all this really snazzy stuff and you can actually Type in a table name like pets and it'll try to autocomplete for you But what I like to do after I've built my database is I just put star And what star does is a wild card for everything So it's going to go through all of your tables and create a model form, which is what you want Make sure that you know generate relations is checked Which is by default and you can generate the labels from the db comments So and you have a form like right here where it says base class. That's a label namespace. That's a label things like that And the code template, which you can modify it by default if you don't like the general Auto-generated code that he uses you can actually modify that So we're going to hit preview scroll down here And it's going to show you exactly what it's going to do before it does anything And it's going to show you the action it's going to take and a little checkbox saying, hey Yes, you allow this so you can never go back and say well ye ate my homework. No you have to tell it specifically what to do And you can actually click on one of these little files and you can see exactly what it's going to do here So we're just going to say generate And uh-oh There was something wrong and this is why I really go over this stuff because it says Unable to write the file dot dot dot meaning we don't have permissions to that directory Well, we need to change that so I'm going to you know do something horrible here Basically what this command is going to do is it's going to go through all those folders and give me Give me read write access to all the users groups and others basically in the entire world Which is not something you want to do in production But I'm just showing you if you're just at home screwing around on your computer now I should say if you're doing this in production A lot of this will be done behind the scenes for you automatically by your web host Now once we've executed that command We should be able to do this so we're going to go ahead and go preview notice how it hasn't done anything So it's still trying to create it and we're going to generate Now it says ta-da Everything's been generated Once in a while There is a bug in this at least in the version that I've got once in a while It will not actually generate this it'll say it does but it won't actually do it You'll have to preview and generate again before it actually does it It's a weird bug. I don't know what the deal is with that So now if we go to models you can see there's a lot more models. There's our accounts model There's our pets model And there's our categories model remember we made these from the database last tutorial And these are a little different. You notice how this time it extends ye db active record Well active record basically says it's talking to the database So this handles all of the database nightmare for you So you don't have to do the select, you know star from blah blah blah update delete It does all that for you in the background all you do Is you create a new instance of this class Modify the attributes you see the name here And then you do class say which will cover in a future tutorial And it does all of the sequel in the back end for you So you don't have to mess with anything That was a mouthful all right, well My cat's given me the come hither look he wants to be brushed. It's his brushing time. So That's all for this tutorial. Um, I know it was kind of short, but it was a lot to take in and you really should you know Get that set up and get it working correctly before we continue because we're going to be using the G code creator quite heavily in the future to generate crud Um Questions comments concerns come visit me on my website void realms.com This is free of charge. I do take donations, but I don't charge a dime for anything I actually don't think even Any of my videos have uh little commercials on them if they do let me know because I don't like commercials Um If you have you know real questions, be sure to join the void realms facebook group There's like 300 of us out there and we're fluent in All different languages and everybody's pretty eager to help each other out That's it. Thanks for watching