 All right, so let's look at chapter UNI 8 and UNI 7. This one here, I actually had two assignments. You know, I wanted to do the WordPress thing, but I think we didn't need to do that. I know you did it before already. So we're gonna skip all that and we'll just go right into the CMS, okay? So the CMS here, it's a content management system. You know what that is like WordPress. We're using Blackboard, it's a content management system. It's a system that allows you to create content. I mean, whether those are graphics, videos, audio, or just pages, that's all it is. And the way to do that is so that you can generate content, especially web pages dynamically, right? Using a single template, you can generate content without having to create physical pages, okay? Otherwise, I mean, imagine you can create like a thousand web pages, HTML, that's a lot of work. So we don't do that. And you would create a CMS for sometimes for a LMS for learning management system instead. So look at that. We'll look at the MVC model a little bit. And we're gonna use this model to create a really simple content management management system. This library here called HTML underscore quick form two. This is part of the peer library. The peer is I think the PHP extension archive library that allows you to automate a lot of processes. We're not gonna go into the quick form two here. It's a powerful tool actually, but it has a lot of errors. And just to have it set up and run program, it's, I don't know why, but it's not really that friendly. Once you have your one, it's really cool because you can create forms very quickly using objects. But, you know, since it has a lot of problems in the past, I just kind of ignore that. And we'll just create forms the way we normally do. And then, okay, so that's pretty much it. So this chapter nine here is from the Almond textbook. Walks through creating this CMS here, which is also the assignment you were doing for this week. It's a lightweight CMS using the MVC model. The way that he does is a little bit different from what I'm gonna do. But the process is still the same. Okay? So let's look at the MVC model. If you remember what that looks like. Let's see if I have a diagram here, I think. What does he, okay. So this photo structure, it kind of gives you an idea what that might look like. So the roof order, and then over here, the way you had here is, it's okay. I mean, it's a little confusing sometimes, but it's okay. So model view controller, right? So the model contains your data. So notice here, I don't think he has a model file here. Yeah. I think he called it classes in here, because models are usually classes that store data. Like in this example, will be like the pages of the content management system and the users, right? You can have other things like video content, blogs, all those will be your model containing the data, right? So those will be in the model. In my example, I will call it models, which just makes more sense. And then we have the views, right? Views will be just the templates, mainly HTML content. The author, and it's looking at users actual HTML file, which I don't recommend, because again, it's not secure, because if it's HTML, if there's any error in your code, you can actually see the content, see your actual code, right? It's not very secure. So they should be, even though they are views, they should be PHP file. And then we have your controllers. Normally you will have another folder here called controllers, and you put the controllers in there. Controllers are just functions, okay? They perform the logic for your website. So you separate your models from the views from the controllers. And since we have a really simple program here, I'm not gonna go to the extent of creating a single object here, and then just point to controller. So for our example, we will just put controllers right inside the root directly. So the index page will be a controller. The page is a controller. We have the user is a controller. We have the log in controller, log out controller. And those are the adjusted logic, right? Not just today. Basically, so you separate this code into the only separate parts. And that's basically NBC. It's a really old model, probably almost 50 years old now, it's not older. But it's still been used today, a lot by many, many programs. So NBC is, I guess you could think of it like a design, even though it's not really a design. It's more of a software pattern. A pattern of how you can break things into your own performance and then how you link them back together to make them work again, okay? So if you have taken, I know Claire did, yeah, taken an Angular React courses in the past with me. Angular, we had to use this similar model NBC model. But no models now are the MDVM, called the model view view model, right? Different Apple uses its own model for Android devices. I mean, for iPhones and then Android Studio has its own model as well. But very similar, it's still based off this NBC model, okay? So the result will look very similar to what we're doing so far. It's just that the pattern is different. So you get a feel of that. And then towards the end of the semester, we're gonna dive into a true object-oriented NBC model called Laravel. And you see how that works, okay? So let's go and then create something like this. I will also put these like CSS images here and script into another folder. I will call it assets because they're assets, okay? Or maybe like public, we wanna call that, that's okay too. And then we'll link the index to the page and then also, I'm not gonna do the login, log out and registration stuff. I don't think we have time for that, but I think just do one or two, you can get an idea of how that works. And so after this, I hope that as you go through the assignment, even though the code's provided, I wouldn't encourage you to kind of just trace the code and look at it and see how they are all connected together. Okay? So let's go into our program here and I'm gonna create a new folder for unit seven. And so right in here, I'm gonna create some directories. And this is gonna be our models directory. To make it quicker, I'm just gonna do control C, control V really quick. Control C, control V and we'll change it just to another one called we should call it use, okay? Our use folder, control C, control V, this would be the assets folder. And what else do we need? I guess we can call it classes too maybe. Yeah, we can call it classes. It'll be like just regular classes for functions, classes will be like database classes, database connection, okay? The database will be there. And then we'll have another folder called includes. The includes here will be things like utility functions, any other includes like the header and the footer includes. If you wanna use function, you can also put HTML. And actually, in this example, we'll actually include the header and the footer as it includes as opposed to a function this time. And okay, and then what else do we need here? Yeah, so again, usually you put a controller so you're not gonna do that, okay? So now I'm going to turn on my exam and we're gonna build a table first. And this will be the same table ending in the assignments. So I'll give you this SQL and you can create one really quick. So go to the admin here. Okay, let me go ahead and then if I can drop, I think it's in here. And let's see, I can find it. And then, what's the chat screen? Okay, give me a second. Bring the chat here, the SQL we need to use. So this is the one I'm gonna use so you can just create a database first because I think the classes are called users within plural and pages. You can use the same database you've been using that's fine or use create one. And the one I'm gonna create is called A, B, P. I mean, advanced PHP underscore CMS, my database and I'm gonna also include that in here as well. Okay, so let me copy that first and go to my, over here, I create a new database. I'll call it, close this, A, B, B, PHP underscore CMS. Okay, and then I just select that, go to import and import the file I just gave you. And so, not that one, let's get it from here. So this is the one, and just click, go down here at the bottom. And this should create two folders, I mean, two tables, pages and users. And again, this is the one I'm using the same one, okay? I just basically modified the pages a little bit, have some extra content in there, but the pages contains five fields, one, two, three, four, five, and then plus ID. And the pages has a column ID, that's for all the pages to sell their own ID track here. And there's a creator ID here. So this creator ID is the foreign key that maps to the users, right? So the users has, you know, their own ID here. So this one is linked to this ID here, okay? So that user two has this many posts, user three had this many posts and so forth, okay? So this is the database design. So that's that and it's running. And then now we can go back over here and start creating our, I also wanna give you maybe some of the files, let's see, move along. But for now, let's go into the access folder, create another folder here for CSS. Again, you put your CSS images and graphics in here, but I think we're just gonna put CSS for now. I'm not gonna have any graphics in this demo, okay? So I'll also give you the CSS, you don't have to type it. This will be the same for similar CSS, CSS are used for the stocks. And I'm seeing if we can find that word there. Okay, I just call it main also. So if you wanna just load that to your page, all right? And I think it's where to go. Copy this here. Okay, so I have my main CSS in here. So let's see, pull the header, that's gonna be in the include. And I'll also give you back to, so you don't have to type a lot, okay? Let's see, where is it at? Hey, HP Miami, it's got me stuck on a low-key screen. Yeah. Okay, there eventually. Okay, so I don't know if it's fascinating to just type it or not, but maybe I'll just, is it better if I copy and paste on this, on the chat and you just copy and paste your code? Is that faster? Oh, I mean, I'm just trying to do the, like import the SQL you sent to us. Oh, now it loaded. Okay, finally. It's just taking a long time. Yeah. Yeah, if you're, just let me know. Cause I want you to do it together so you can get this. I wonder if my VPN is also making it slower? I don't know. Are you putting it on Apollo or are you doing locally? I'm just to HP my admin. Okay. There is kind of blah. Okay, in the meantime, I'm going to go and give you or in more, a couple more files. Maybe that's, let's see. I have to CSS file downloaded and stuff. It's just this part that's taking a while. Yeah, I will also give you just the header and footer so that, let's see what's time. This is just put it includes, okay. And I'll put that in your chat also. So here is the header. So notice I'm using, we're using dot ink. Just, you know, it's include the dot PHP file. And then the footer as well. And so basically, you know, you build the page first and then the way you like it and you break it so far, right? And then you break it into, it's like you just slice it into the footer and the header. So those will be the same across all sites. And then in between is the content, okay. So that's where all the, that's what the views come in. The views, we just have these inside the body content right below the navigation, okay. So in here, I'm going to add that to, I don't think I have anything that functions. I probably won't use that, but the header and footer. I'm going to put those inside my includes. I don't want to factor this. Okay, so if you look at the header, this is a file. So on the top, you have your meta tags and you're going to echo the title page up here, right? If it is set, then go ahead and then add the page title. It's a variable. So we'll just populate it here. So every page will have its own separate title because we're going to include that on the actual page on the controllers, right? So it's a little bit different from what we did before. You could put this to a function, it's fine. But if you use the function, then you have to pass the page title to that function. So you can display it, okay? So in different ways. And then down here you see a variable called user. If user is set, then go ahead and show the log out. Otherwise, they need to log in, right? So that's what the log in logged out here. Again, we're not going to implement this, but we'll just force the user to be logged in already. And then here, again, register, I'm not going to do that, but that, this is the navigation part. And then I caught up right after the header here. Okay, so in between, I'm going to have my index, my page, my user, registration, whatever it is. So we'll just contain this part here. And then it continues on down the end of that. And then at the very bottom, you have the footer here and then you close container tag, close the body in HTML, right? So they all stitched nicely together. So now I'm going to go and create a index file and the root directory of this project. This will be the learning page, okay? So that's for that. So what does it contain? Well, it's going to contain the view. So somewhere up here, I have in here, I have included view of the index, okay? So before we do that, let's see, let's see if, let's see the view for the index we're going to have, what do we have for the index, right? So in the view here, I'm going to create an index for my view, okay? I'll call it index also, I guess. You can call it view underscore view.index, if that's better, but that's okay. So this is my index, number is in the view directory. So what do I put in here? So for this one, I'm just going to leave it, just like it just contain main HTML. So it's going to start right below the header right here. I want to main tag because my container's up here, right? My container's up here. Then the header for the navigation, then now my main content starts here. So I'm going to put main and they're close to main load bottom. And in between here is where you put this stuff, okay? And this is going to be the actual content. So what does it have in here? Maybe I'll put a article section. The inside article will put the H1 and then we'll put here like the page title or like the date. And then, oh, how are we going to do this? Doesn't really matter. Put a date here and then the title here for every page title, something like that. And then right below that, maybe you put the paragraph for intro to the title, the article, right? And then below that one, you put a link. So maybe I'll link it to a page, PHP. I'm going to include ID and ID will be based on, so this probably generated automatically using scripts, okay? I'm just putting it for now. So it's a skeleton and you can see what it is. So the ID will be a particular ID, like for example, the ID through article, like article 12, okay? And then we'll do that here. I just put that article for now you can see and then we'll put here the article title, right? More about that, right? We'll read more and whatever it is. And then we'll do that on every page. So if I were to, you know, just let's say if I do that twice, like that. So article 14, whatever it is, okay? Title, title two and then title one, just demo, okay? So that's my main content. And then that's going to go between my includes and inside the index page, it's the landing page. So the top is my header. So you put here include the includes header, right? That's the header. And then I'll duplicate that control D. This is the views and then this is the index views and then this is the footer, right? That's the logic. And so this is the controller, okay? The index page is the controller. I put here controller page. This one here is the view, okay? And then the model is in the database. So all your pages will look like this fashion. And then, so the title page notice and the header file, it's below here because I need to access the title, the page title variable here, right? It'll replace that. So if you want to use the same variable in my index page on the very top control, I will set that to a title here. I'll put here, maybe the home page. So that title will go into the includes when you stitch this together. Even though, right? You know, even though the includes file, it's not, doesn't have a page title here. It will be set and use it once you put together, right? Same thing with the user. I don't have it here, but that will also be a stitch together. So you kind of have to map this out together and then it will display the main body of the content to this place and then as a footer at the end, and then we're done. And let's see the header, does it have link to CSS? Yes, it does link to my CSS already. As you can see, for assets, just as in main, if you don't have that, if you have a different structure, just make sure it points to that CSS, okay? So basically I've built my little simple model you control it, okay? So what kind of views do you have? Well, it depends on what type of pages you're gonna have, how many things you're gonna have on the site. The index is the index page. I couldn't call it home as the template, but I call it index, it's the same name. And we don't do any database connection yet, but I want to test and see what it looks like. So go ahead and run the browser and see what it looks like. So here we go. And I have a problem here, so the user is not found, that's okay. So at least it's working. You know, I have my navigation top, my footer, and then my content goes in here. And then this will be dynamically generated and so on. So this message is the user is not found, this variable here, because in line 17, I don't have the user created. So to see that, to remove the error, you have two options. You can create a variable user like in the header area up here, I mean like in the index, you can create a user here, just that null. Let me see if that goes away or not. Okay, so you can see it goes away because it's visible everywhere around here. So I will take care of that. So now my page looks pretty much already like this together already. We just have to connect to the database and then generate content. And then it will look very similar to what it has here. Not if it showed the long end now because the user is set to true, not true, I mean it's set to, the user exists, right? It checks to see if it is set. It's not set meaning that it's known, I mean down here, if a user is not present. But this will be an object, okay? Usually an object of the user class. So then let's go ahead and create our database. So that'll be inside the class. Go ahead and create a database file. I'll call it bb.php. And this will be a class, so class db. And we did this before. If you remember, you can copy and paste it over if you want to, but I just wanna create some constants here. Now all of them, we'll use PDO also, so you can have a more, yes, experience, right? Inside here, we're going to use a public variable called PDO and then our constructor in here will be under under and then constructor, just hit enter. We'll have a function here to connect. So we have that already. So we have similar to before. Connect, missing something, public function. And then inside the constructor, I'm gonna call that function connect, right? So this db connect, not need to connect, just connect in this example. So PDO, from the point here, we can do like we did before, create a different variables to hold the, you know, to hold the database or we can just connect directly. And for this example here, I'll just do really short, okay? Short connection. So we'll just say that this, go ahead and set this PDO to new PDO and then here is the strings, right? If you remember, I'll put a separate line so you can see. The first one here is of course the, it's a string, right? It's a long string of, actually, you know, it's not confusing. Let's go back to the string. It's a string. The first one is the driver. So you know, you use the variable and put driver here and you will do that, but it'll be just my STL, driver is that. And then the next will be the host of a domain, right? Host is a local host. Again, from here on the order is nine point. It's a key value pair, right? And then the db name is going to be adbphp underscore CMS, the one we just created. So that is the, this part is just the DNS part, okay? So we have, we've got that one done and then the next thing is the password. I'm going to username your password. So username will be just root and then the password is blank. Okay, so that is our connection string. And constants can go up here if you want to do that. So you can define a, you know, maybe this way it's better that the user and we're like, so user, no, I just, I'll leave it as this, but usually you put it to your variable name, but I put it here, I put a table, the table name. So I have a table underscore user and then this is mapped to the users table and then we'll do another one for the pages. And then here would be pages. I think I'm sorry, okay? So those are constants and we can access those throughout the program. So remember that we connect, I did not do any security stuff. We want to wrap, it's for the tri-cache block, right? So let's see if it has one, see if I select this line here and right click, doesn't have surrounding. Generate, don't want to do this, it's surrounded. Anyway, I want to try this, okay? We have to try it, okay? So this line needs to be inside because it might have an error, right? But I try that, if there's no error, then we can catch it up, if there is any error. And here will be the PDO exception, okay? Not the exception, but the PDO exception we'll call it E or error. And then what do we do here? Well, we can just show an error if you want to. And we put the error, so we can see. I put it here kind of like, no, actually, no, let's not put error. I'm gonna create another view, okay? The view will be inside here for the error. And we just do really simple here. So let's create another view here. In fact, I should just copy the index here, it's faster. What I wanna do is this, okay? So when you get an error, then I'm going to put a variable called pageTitle here. It's equal to like error. And then we're gonna load the, let me try this again. Include the includes and the header.inc. If you put it into another function in one. Include that, also include the views and then they have the error message page. And then you have to put it both down here. And then once you do that, and then you wanna call exit so that the page is exit nicely, okay? So that's what I wanna do. I already have these, and I just need to add the error page in here. So we can go ahead and then copy the index here. It would look very similar, right? Copy and paste and change it to say error. But basically, this is our connection string, right? It is a successful failure. And we want to be able to output nicely, a nice message to the user. And then if you wanna go to the error page over here, we're just gonna, we're not gonna have all of these. Let's put a very simple message in here. I put a type, the E, click error. And they will put the error message right here. And then we'll put it here. That, right? Close that. And inside here is the E get message, okay? This E here doesn't exist in this page. It's placed, but it's called E. You wanna use a different variable. That's fine too. I use E because inside here, I call it E. Okay? So the page title will be injected into the header, which is here at all the information here. And then it's going to launch the error page. This is the view again, right? And then you just have one simple message here and a main page. I don't have to actually, I don't have the article here. You can take that out, just reassemble like that. And then you print the error and then print the message here. Save that, and then you stitch right back the footer and then you exit. Okay? So that is the connection for that. Notice this is an object class, okay? When we created object of the DB class, that object, whatever it is, it's gonna have access to all these variable called PDO and functions and things like that, right? Okay, so assuming that's have too many semicolons there. So that's that. And then the next thing is right away, we want to retrieve some data. So that's going to create that in here. Some audience like common operations are right in here. So this is for get all pages, okay? This is just, just do what pages in here, just do this. You can see it, the function, call, get all pages. And like before, when I pass to this function, I need to get the table, even though I know it's for pages, but I'll put a table in here, okay? So a variable called table, and I'm getting all of it, I don't need ID, right? We know that. I'm just gonna call the table to get all of them. It's just one go. And then in here, this is the query you wanna use. Query, you can select everything from the table. Let's see, to select everything from the table, let's see what happens, okay? Select everything from the table. The table, and you can also order by date, add. Remember, our database has the date, add, let's see. Over here, we have the date added. So let's sort it by that order, if you want. The one sorted, that's okay too. Let's say table and then order by date added. That is the query, and then we're going to run that, okay? And then we'll return the result set. So the query will be like this, PDO, query, the query. And then remember, this PDO query returns the result set, okay, returns the result set. And we're gonna return this entire result set to where it's been used. So in this case, we don't have to do any of those prepared statements because nothing that we added in here. If it's using the where clause, then yeah, that would be needed. And then that's where the next one comes in, okay? So for now, let's add another one down here. This is the function get one page. So you need the table and you need the ID. It'll be kind of similar, I guess. So we'll just copy this line here. And I'm not gonna order this by anything because once you're gonna get it, you don't have to order it anyway. But you do need to get the where clause, where the ID is equal to, and again, if we don't wanna be equal to ID like this, okay, I want to secure it. So you can put a question mark if you want, or you can go and use the ID route instead, right? So I'll use this one here. I mean, lots of ways. And then once we do that, we're going to prepare this query because we don't want injection. So you would use the statements. It's equal to this PDO and then prepared. So we prepare the query, right? So that's prepare it. And then now when you find it, you have a couple of options that I showed you last time. And since we only have one variable, just the ID, you can just use the bind, a prepare bind. Other ways you can use the array as well. But I guess it's easier to do that. So we'll just find your, okay, finding to the statement, find programs number one. Round, similar. And then we're going to bind, change two parameters. Since we know the variable, if you put a question mark like this, right? If you question mark, then it'll be the first position. So you'd be one and then the data. If you're using the actual variable name like this, then instead of one, you put the ID here like that, right? This one's going to match this variable here. And then this is the actual ID. So if you're using variables, use a variable. If you're using just numbers, then the order is important, okay? We bind that already. And then now we're going to execute it. We're going to execute. Notice it's different from up here. We're using PDL to do a query because we just do retrieve without any data injection here. This one here we're using prepare because it's scared of this value here, okay? So now we're going to do a statement, execute. And we're not passing any parameter to that because we already find the data here. Otherwise you would pass the data here and you don't find it. So either way, it's up to you. And then when we run this execution, you're going to get either a successful or not successful. You got to get a role change, right? Either a zero or one or how many it is. So I'm going to return that value over here to another variable. And we can call this one here like no result, okay? So the result is either successful or not. And I'm not going to return result because this one here is return true or false only. So it's not useful and want to call elsewhere. Why? Because I want to be able to fetch the data back, when you fetch the data back, you're going to fetch it through the statement object, okay? And so by that way, when you fetch it, you want to be able to call the fetch function. And the fetch function is part of the statement here and not part of the PDO. So that's why you want to do it here, check to see if the result is successful or not. So you can do like, if result is successful, then go ahead and we to return something, right? If it's not successful and down here, you'll return just null. This is the default, if it doesn't match, but it does match, then you want to fetch the data, okay? And you put here fetch, fetch data, and then so the data will be the result set. So it'll be similar to this part here, fetch the data, and then finally you will return the data back, okay? So we turn the result set to where it's being used. So we get the similar result, return a result set, return result set, okay? So we'll come back and do this part. So for now, we need to create the models. So in here, the models are, we have two tables, so one for each table, okay? So let's see, the tables in here, then I create a page called page.php and then we'll do one more for the user. Okay? So the page in here, I think yeah, it's gonna be quite a lot. So I should just give you, I'll give you that too. I think I already have it created. I think I don't change anything from the example in the book on this part. Let me see, all right, let me just share this with you again. So in the models, yeah, this should be the same. I'm gonna drag this to and give it to you guys, okay? It's faster, I think. And I should do this in here. Thank you. It'll work, and I'll just explain. So the page for the user first, user, we have all the IDs and muting paths were here. Again, I'm not doing the registration here, so later on when you do the assignment, we will do this, I guess. I don't know if you had to want that, but this will be just for the user. And all we do here is fetching the user ID here. It's a bunch of gathering centers, right? Which had to see if the user is an admin or not, right? This is admin type set in the database. So nothing much here, just a key function for the user. The page database, we have again all these seven fields in the database, okay? This will be the actual fields. Constructor doesn't even here. And then we have bunch of gathering centers, okay? So get the ID, get the, this, the creator is the user ID. This is the actual page ID, the title page, the content, and then so on. So these are coming from the database, okay? Because it's an object, right? It's a class object. So instead of, you know, making query every time we call this function, we will query from the database here, okay? So when you get one page, I get the result back, okay? And then if the result is found, then I'm gonna fetch the data using this result. I mean, this statement's here. So let's do that here, okay? So we have the, that included. So I'm gonna fetch the data. So that means I'm gonna use this statement here. Remember that this thing I showed you last time has a lot of function you can use. And you can fetch by just a regular fetch. You get result sets, you get a regular result set like this. You can fetch it to another array or you can fetch to an object of a class. So we have object, a class called page, right? So the signature or what you call the shape of this page has exactly all these six fields, seven fields that will match our database. So when you fetch it back from the database, all these fields will go right into the object. So you can have a really nice object here. So here you have a function called set the fetch mode. And then here you can set to PDO, colon, colon and you can see here if you type in fetch, right? You have the fetch mode to associate both class type, column function, you can set to another function, so on. So we want the one that says class, okay? One that's fetched to a class. And what is the class gonna be? It's gonna be called page. So this one here sets that for you. This statement object now prepares to fetch the result from the database, all those seven fields and they gotta match this page object, okay? This class here. This class has exactly the same footprint. If you don't have it, it's gonna fail, okay? So it's that same footprint. Once I get the set up, then I need to go in and then make the fetch. And then so here, I'm gonna do a statement.fetch Go ahead and fetch it. It wants to get the result set. I'm going to assign to a variable called page. So my page object, this is an object now, okay? I basically instantiated object of the type page because this one here knows that the mode I'm fetching and return a result set to an object of the class page. So this is similar to saying like, you know, page is equal to new page, right? If you do that and then you add every field manually yourself, but PDO is nice because you'd have to do that. Once you assign that, the result set only comes in each field assigned to the page object and now this is the object of the page class. You could want. And then once you get it done, how do we know it really works or not, okay? What if the data doesn't come back and it's nothing or it's something. So you have to check it first. So you have to say if the page is really there, if it's not known, because if this function fails, then the object will be known. You never instantiate the object. So if it's known, then we don't do anything, right? Otherwise, if it's not known, I mean, if the page does have something, then we will return the page. Otherwise, it will skip, the whole thing will just skip and then return no now, okay? So it returns the page as an object, the object that appoints to this class and this is for fetching one page. And this one here fetches all pages, but it returns not an object of the page class, it returns a query result set. So there's a difference there, okay? So we'll see if this works. So that we got those done. And then now what we need to do is we need to instantiate database connection. So my way of doing things was to create a config file, right? So if I close all of this here, I need to create a config file, that will stitch everything together, okay? And so here I'm gonna turn on the session. So I don't have to call anywhere else. Once I include that in every page at the top, everything that the session is on, I need to include here the DB and all those other stuff, right? I need to include all this thing that I need. So that's in the classes DB, DB. I need that. I need the models page for the user and the models for the pages. And I don't use the function, but I mean, why not? Not yet, but that would be the includes, what did I put it? Yeah, the includes and then the functions. So I'm not gonna include the, do I have it here or don't? Yeah, I don't have it, but if I do have it, it would be there. So let me turn this off. I don't have it. So notice I don't include the header and photo here, right? Because these are actual, actual content, right? So I don't do that here. Because if you do that, then it'll be rendered right here. And you don't do that because these are only added to the actual, the controller pages. So that's it for this one here. And then I need to create the DB object. That's gonna be the new DB class. And then I need to have the user. Actually, no user don't need it. Yeah, why not? You can have it, it's fine. Because we want to set it so that it's visible every page. But usually you don't create until you log in, right? After you log in and you create a user, but for now that's okay. So that's gonna be injected to config add to every page. So I'm pretty much done here for this one. And now if I go, I start from the index page, the landing page, right? I got my title, I got this. So I need to have a config file. So I notice I put user here. So this time I'm not gonna use it because I wanna use it from the include. So that only contains the user. So it does the user, it does the database connection. If there's anything fails, it will crash here. Otherwise it'll go and load the index page and so on. So right now you wanna save it and run and make sure it still works, okay? And let's see. Okay, so it still works, right? If it crashes, it has an error, you wanna fix it, but so far so good. And just to make sure it does, does, does work, right? You can always go to the database connection here and I put the message, okay? Right here, if it's successful and echo it. So we put here, so we can see that it's calling the database and then we just turn it off. I can't see it, I think it's there and you can't see it. Because of this navigation, but let me see the X-Qual key would do that for you. You see it's in the page source. You can see up here, right? Success. Okay, it's hitting up here. So we know that it's working and then I can go back and turn it off. So, all right, so I wanna just say that we caused an error. All right, let's see what happens, okay? So let go ahead and let's go and put here, I put like in the valid database for like a TTT, whatever. And then it's gonna load the error page. Let's see, that's true, I don't know. Refresh it, right? You see they load the error page and notice the error doesn't have the, I did not put the include inside the error page for some reason. So you get some errors in database, it's not known. So notice how dangerous this is. Because I'll put the message and you never wanna do this to the user, to the public, okay? Because they know that, aha, so you are trying to have a database look similar to this. Now I can hack it, right? So we never wanna do that. Just say, you know, can that connect to DB or something? So people don't know. But it does load the error page, but that the view, if you look at the index, the URL, it still say index, okay? We never load a error page, we just load the same page by different content in the body. And the error here because we don't have the user again. Because when I load it here, I did not include the config, right? So over here, my config file has everything I need. But I don't wanna put that here. If I do that inside here, I can have a loop. So normally, you know, you don't wanna put it here. You will load another function or another include and put it here. But for now, that's okay. And then to remove the error, you can, the warning, that's not an error, okay? This is just a warning. The warning me, it doesn't crash your pages when you just see it. But you still don't wanna show warning here. And you can turn this off, on and off by, I think you have a function called error reporting. It's a reporting here. And then inside here are some constants. And then inside here are some constants. And can you just say, is it warning? Yeah, you're warning here, okay? If you turn that on or off, I don't know if it's too long. Let's see. Yeah, that's on. Or if you don't wanna put errors, just put zero. Zero means no, let me see. Okay, so the zero means turn off all those warning errors. Not only warning, but also messages here. So if you wanna turn that all off, if you want to pick and choose only the type of error you wanna put, then you specify the numbers here. Even though this are numbers, you can also put the actual constant, right? If you remember control tab will tell you, I'll control spacebar. E warning, these are the constant variable or you can use the number themselves, right? I only want to display all the warnings you put it to. I want to display only the fatal errors, you put a 16 and then a one, whatever it is, right? You can pick and choose. If you don't wanna put anything, then put zero. And then the zero, if you go down all the way to the bottom somewhere, it'll be zero, it'll be no. Or if we put zero here, and it will turn off the warning. Just for this page here, right? So we have an error, it says desk work again. So you go back and change it back to the normal one. Save, refresh, and then we'll back again. Okay, I think it's break time. So see you in 10. Sounds good. Okay, okay. So we got that working. And then the next thing we wanna do is go ahead and load the data to the front page here. And that should be easy now because we already have the database connection. We're gonna get all the pages as opposed to one and we'll print the data. So go to the index page here. So notice again, the logic is here, right? So before we load the index view over here, that's this guy right here, right? It needs, we need the page object to load its office page. So the title, it's part of the page, right? You get the title here, you're gonna get the title, get the date, the content in there. So in the index page, before we call this function, I just did that because we wanna see what it looks like right off the bat because once you have that the way you want it, then you can go ahead and perform the logic, right? So right here before we call this file, we include the header, okay? And then right here, we can go into PHP mode again. We need to do the fetch stuff, right? Oh, come on. You're already under PHP. Like it's already says PHP on the very top. Oh, I did, okay. Thank you. Okay, so we're gonna try and catch here, okay? Again, just in case, so that we get any error, we're gonna handle it. So I'll put here again, E. I do this because inside I'm gonna do the DB connection. And once I have the error, then it's like before, right? You're gonna put here the title, page title. It's gonna be error. And then now I would include the header and the footer. So all that I need to do, is very similar to what we did inside the database here, right? Notice I did up here, right? Just repeat it. Audi had this and that, I just need this part, okay? So I need to load that error view to the view. So that will go right in here. And I have to override my page title, otherwise it would say a home page. And I don't want that, right? It needs to say error page. So load that and then that's it for this one. Now the try block, the view here needs to go inside the try block somewhere here, okay? That's the logic, right? But before we even load that, we wanted to do the DB connection first. And we want to load the DB. So we get the result. It's gonna be from the DB. And then we call that not connect, but the get all, okay? Notice I have a lot here, because all these are coming from the different, you know, units, so it's gonna be confusing. That's why I'm just kind of bad at doing this. So usually you can do it in your own folder, but anyway. So the one I get is the one that says get page. Get all page, okay? Right here. Let's get all pages. And what I need, I need table and table is called table pages. I pass that to it. It's gonna pass going to that function. You control click. Go right in side here. Get the data, get everything back. Return the data result back. You don't only be successful on that. I did not try here. It's okay because I only try in here, right? It's only try here. So it's gonna copy it anyway. I catch it. If there's an error, it's gonna catch it down here. So when it comes back, need to check if the result is there or not. So here's the result. If the result is successful. And also I want to make sure that we actually get some data. Successful, but maybe, you know, doesn't mean that we actually got data back. It just be that maybe something is okay but there's no record, zero record. And also I want to make sure that the result set, it can point to a function called roll count. And that will count the number of rows and returns. And it has to be greater than zero, okay? Otherwise there's no data and then there's no point of continuing one. And that is the case. Then go ahead and I'm gonna go and keep moving this inside here. Otherwise I have an error. So something is not so else to put here. You can throw an error here. I can throw an error because this is, the result is either zero or something fail. Right? And then you can throw an error. You can force it to throw an error. And this, oops, the exception and then the exception. Now I want to do a new exception. Okay, so new exception class. And then this section, we pass a message here. Once you throw it, it's gonna be caught down here anyway, okay? If there's an error in here with the DB thing, it's gonna throw automatically be caught down here. If you throw explicitly throw, we'll catch it on YouTube, okay? So I want to throw an error, something like no content or something wrong, okay? I don't know what that is, but I know that something's wrong. You're gonna throw that message, go to the E and then E will print out in the error message file. Because in the error, it prints the message in, okay? So now, if it does have some stuff, which is good, right? Then we do the same thing as before. Okay, we're gonna fetch it, right? So do a result, fetch, set the fetch mode. Back to that again, the PDO, O. And then we want the one that says fetch class again. And the class again is still gonna be page, just like before. So we set the result fetch mode to that page. And then now, if you look over here in the DB class, we got that, right? We fetch the mode, and then we're gonna do a page equal fetch statement here. You could do that here if you want to, it's okay. If you do it here, then you have to modify the index page view here to change it. The index view, if you open that, you see that we do the, I don't do it here, but you can do the fetch inside here too, because I know that I set the mode here. And inside that page, do I want to, on the index, do I fetch it there, or do I do it elsewhere? So a lot of options. So let's say that I'm gonna fetch inside here, because I use a loop, and loop to the entire fetch, and then I'll do an output here. So I'll set this up. The result is good to go. I include this in here, so the result is visible, right? It's visible inside the index. So now up here, I'm going to go into the PHP mode, okay? And then I want to do a while loop. While something is, I have content, right? That's what I mean. Go ahead, I'm gonna delete one of these, I just use one. So this will be repeated inside the while loop. So I'll do here, I'll close right in here, and then this part goes right inside HTML mode, and then down here, I go back to PHP mode, okay? Just close that curly here, that's all. And that's in semi-index. So I'm gonna have a lot of articles inside here. So what's gonna be tested inside here is the page. So I have a page object is assigned a result, result, right? This result here is, this result here, it's right in there, right? The result, I'm gonna fetch. Oops, the result is gonna fetch it, that's all. This is how we set the type. I know the arrows, the red lines, it doesn't exist, but we know it exists. So while there are pages, so it'll fetch one at a time, add it to the page object, and then I go out to the HTML mode, and then I'm gonna add the date to the line here. So the date I put here, doesn't matter how you do, okay? I just happened to put a date here under the title, you put a title and then a date below that, maybe it makes more sense this way. The title here, and then down here, we have date, right? So the title will be, or replace this now with this page, it's an object, remember? The object of the page class. So, right, get the title. That function is inside the page class, right? You're gonna get the title, get the creator ID, get the title, get the content, get the date, add it, update, all that access through this page object because we assign this result to the page class, okay? So page title goes here, this will be your date. So if we're here, oops, page get date, add it, I think. And then this is the actual article. So put it here, the page, I think that's the intro, get, control only, not the actual content. And then we have the ID here, okay? So instead of 12, it's gonna be that, and then dot, not dot, I mean, equal. People right inside here, I think that's fine, right? So, page get ID, there you go. And it's gonna loop that into how many articles we have, we're gonna render that to the index page. So this is the view for the index page. It'll be very similar to the actual page when we load the page, so the page controller, for example. And we can, I think it looks good here, but let me go here and then reformer my code, okay? So a little bit cleaner, save, and let's give it a try, put in a browser, and press a page. So here we have the pages, okay? I didn't put into like columns, but this is the first post, and then the second post, and all the way to, I didn't limit my post, I could just limit it to only three or four or five, but I put everything here. Formatting it just, it's something else, but for now, you can see that the title and then the introduction here, and then the actual content. If I mouse over this, you notice on the bottom left, the ID is four, put down here, ID is seven, right? So page, we're gonna go to the page controller and get the ID, and then show the detail of this post, or this page. Mine's being weird, but it's just, I don't know, it's like, it doesn't have a database selected, but I do, but I have it connecting to the database on PHP, my admin, so I don't know if that has something to do with it, or if it just doesn't like me. So you're not able to use low data? Yeah, hold on, what was the error again? Yeah, it could be... Invalid catalog name, no database selected. Does it tell you what line number it is called from, and which file? No, it just says SQL state 3D0, so there's something invalid catalog name, 1046, it just, that's all it says. Like when I tried loading the page. It just happened now, right? When you access the get pages, before I was looking fine or whatever. Yeah, I mean, I got like the little success thing before, but I also couldn't like intentionally get it to like crash, like I couldn't get the error screen before, because even if I just punched in a bunch of letters for the database name, so I don't know, something must be weird, but I don't remember how to like load it, the database into PHP storm on its own, so I've just kind of been going with this. Yeah, I think this connects somewhere. Yeah, whoops. Okay, well, if you're able to connect your database, you say it was successful, right? So I'm thinking it probably has to do with the query here, when you do the fetch. So like in your fetch statements down here. I'm not sure if it was connecting to begin with, to be honest. Okay, well, what did you call your database? Did you call it, because I forgot, your mind is called advanced DB PHP, okay? So you have this content that you are at your database? Yeah, that's all on PHP, my admin, that's all on there. I had named mine like jprony underscore ADV PHP CMS, and I didn't like my password, and that's where I stopped. So that's that, so the tables, remember they are plural, okay, so if you put it in your code. They're all in there. Are you able to connect? That's the part where I'm not sure, like it's, in the CAP statement, it says the page title isn't used, like where it switches to error if it crashes. For the include statements, I had to like, in order for it to even find like the header error stuff, I had to like put the whole path starting with the root directory all the way down, for some reason. You want to show your screen? Yeah, I can do that, that might be better. We can do that, take a look, let me stop sharing mine, you can share yours. Take a look. Sorry, I was... Problem? Okay, so, okay, see like this is like that, like... Okay, so page title is there. This part never runs, even if I intentionally crashed this, this doesn't run. Yeah, the include, the include you don't have to say unit seven. Yeah, but like... Yeah, you, because you're already inside the DB, so you don't have to say that, just say includes, yeah, includes and then header, then includes views. Yeah, that's weird. Yeah, you mean that. Yeah, because you're starting from the root directory, okay, which is in this case would be from the demo folder, or the unit seven folder, right? Yeah, I guess it's seven and I have the demo folder because I'll put the assignment for this week also in the unit seven folder, because that's how I haven't arranged, but I like this right thing. But anyway, this part doesn't run at all, like unified. So your index is outside of the demo folder? It's still in the demo folder. It's just... Okay, so you run it from the demo folder, okay, I got it. And then the views, the other one is in the views folder. Yeah, okay, so that's fine, looks good. And then config folder, config one's in the same one. Config is includes, models, models. Okay, yeah, that looks good. DBE, okay, that's fine. I don't think it likes the fact that I have other stuff in here. Yeah, that's fine. And so usually, I mean, we'll create namespaces, so it doesn't get confused, but that's besides the point. All right, so that looks, I think that's good there. The get all pages from water by date edit, all right, that's good, return, you know, query. And that's fine. You get one page, we haven't called that yet, but we'll see that in a minute. Okay, let's see your index page then, the actual index page, not the view, but yeah. Good, this one, yeah. Yeah, so you got a title, you got a header, good. And then had your page result. But now when I run it, it'll actually run this. Yeah, let's try it. Okay, that's good. At least something there. Yeah. Right, so maybe you didn't select your db, let's go back to the code again. In the pdo, in a db connection, a db file. I'll go up to the pdo. Okay, so post apollo, gtc, db, instead of db, you had to say db name. That's where the error is. Yeah, it's just db name, it's pdo and just get the number. Yeah. Oof, now it's one. Yeah, you got one. Let's start. Yeah, so let's see, do you only have one? Is that one? Could be it. Yeah, let's see, this doesn't. Okay, because you didn't add the code yet. Let's see, result fetch, and then yeah, do you only have one in your database? No, I just imported this, there we go. Yay. There you go. Perfect. Yay, cool. All right. That was a hard one, but now we fixed that. Same. It's the db name here, okay? So these are really, really tricky. The driver, the close, and the db name. All right, so we got that going, and then now we are going to create the result pages for every page that we load, right? So we click on that link on that new page over here. When I click on this, it's gonna call it load the page and then we're gonna get ID for the query and then we load the content here, using the get a single page. Right, so in here, in the view, we're going to create something kind of similar to the index. So I'm just gonna copy this index here again. Control C, control V, and we call this the page. And I can close the index view now. I have to maybe config and be closed. The page can be closed, error can be closed, header here, all this can be closed. So open the page file, index can be closed. So what do we have in the page? It depends on what you want to show here. So we want to show, you know, the same as before, the title, the date added, we need this, this, not the intro anymore, we're gonna get the content. So I'm gonna here get content, because we have the full content here. And then down here, I'm not gonna put the link here again because, you know, it's already done. I'm not gonna show more, everything will be loaded here. Now up here, I do the fetch here again, we'll leave the askings for now, but let's go and this is the view, by the way, right? We're still gonna come back and see if this is the way you want it or not. Let's go to the main index page and let's duplicate this index. We'll look kind of similar here anyway. The difference is just we're gonna call the single function. Okay, so control C, control V for this index and call it page, so the page, controller page view. Okay, so again, sometimes we wanna call it view and then view view, not to confusing. But open that page controller and we include everything here in the title will be page for now. And then we're gonna call the function, not get all but get one page. It needs two things, okay? It needs the table and it needs an ID. And we're gonna put it here for now, so placeholder, we're gonna get that ID. So before we do this, we need to load or get the ID from the index page, right? Because the index page, when I load it down here, I pass an ID in the URL. So before we call this result, we're going to get the ID. So we'll say if the ID is set, actually, if it's not set, right? If it's not set, you can say for the underscore get ID, that is not set or that's fine or you can check it. So it's not valid. There's a filter, a filter, so that only takes integer. And that is, you can add it here too. Maybe it's a filter function. So it's not filter attribute, filter bar. Okay, this one here, filters the data type you want to get. You want only to be integer. So I mean, you can check in manual if you want. If it's not set, it do something. And if the ID is not a number, they do something, something, right? You can do that manually or you can do all and one go by using this filter function. This one here, we'll check to see if we get ID is a number, okay? So this function here takes I think two parameters or three parameters. That is the field I want it or the value I want to check and the filter type here, if you put filter, you take, you see a lot of things here. What type do I want? Similar to how we do the fetch here, one more and one. So the filter type I want this to be integer. So if it's I want to validate this, you go down here, that's one for validate right here. Validate, it is an email, a flow, an integer, I wanna say I want to be integer. You validate that to be integer and you can stop if you want, okay? We can leave it here. What if we accidentally, somebody accidentally added an integer of like a negative three, right? So negative three doesn't work because and the ID of the table, you cannot have negative IDs. Okay, so you can add another attribute here. You can check to make sure that the array and the range there is an array function called the minimum range. This one here has to be greater than or equal to one, right? So the ID is always starts from one in the database, right? In here, you cannot have a negative ID here. It cannot be a negative, it cannot be less than one. You can have zero, okay? So it has to be one more greater. So therefore, if that is the case and then we're good, if it's not the case, right? If it's not set or it's not, doesn't make this criteria, then we have a problem, okay? So the problem is we throw it, throw a new exception. Say invalid ID or average. We throw that error. Everything will be skipped and then we caught down here and then we displayed here. We can test that here, okay? And if this is not true, then we're good to go and then now go ahead and get ID from the get ID. And then now we can pass ID to the get one page function and then call that DB function, okay? Okay, so notice when we call this function get one, you go back in here, we get one, right? The end result is we return a page back. So the page is already that object, okay? Or return null. Object is also set to null if it's never been created, right? So that's object is. So either a page that contains the actual content already, a single page is only fetch one or null, okay? So therefore, when it comes back, so this is not gonna be used here. So instead of saying result, I'm gonna call it page because the data coming back is already a page object, okay? And then when, so I'm gonna remove this whole part here and we'll do if still. If the page is not null, right? That's what it means. If page, I mean, it's not null and then we'll go ahead and include that page here. If it's not null, then go ahead and the views will be not index or be a page. And then if you look at the page again, put over here so you can see better. Oops, the page view. Okay, so we gonna fetch the result. That's what it says in the view, right? So that means the page has been created, which is good because in our page, that's what we get. We got the page ready and then we just go ahead and then fetch it. It's your page. Otherwise, if the page is not successful or if it's null, then we have no content. So again, we throw it under error and again, it will be caught by this one. If it is successful, going to load the page and then add the content, the title and then and so on. And this is actually not correct because we're not looping through the thing here, right? It's just a single page. So really, we don't even need this. We're not gonna do a fetch again because we already did it inside here, right? We already does the fetch here. We already got the content we need. So when it goes here, successful, we load the page and then we just use it, okay? So this thing can go away. This whole thing can go away. So all these can go away. The HTML part actually can go away because we just gotta load the content right away. You get the page title, they added and the content. And then we clean this up. So it's much more than the other one. And if you want to allow the user or there's the owner to edit this page, you can add edit link here. But if the user is the owner, right? Otherwise, don't edit it. You can put it here or you can include in the index right here. You can add so that after each of these articles, you can put an edit mode, but you check the user. If the user is present, then go ahead and edit along with the ID. Otherwise, don't, right? So what now we're just gonna do without any of those edits. All right, so let's go back and see if it works. So we go, put in the first one. And I got error. I probably mistyped my error page, 41. So my DB has, yeah, the term page, I have an error here. Okay, this should be a dollar sign, all the time. So let's try again. So there's the article right here. Okay, so we get the ID four and then it loads. Good. Go back to the homepage, load the another one here. Good, okay. So we load content, dynamic content using a single page controller called page and we pass the ID to it. This is kind of similar to how you did with the cars and planes and boats, do you remember that one? Right, we have a single page, we load the ID and we load the content. That file or that program, we did not use controller in their views because it used a lot of if and else block. But here we're using controller in views, okay? So now we can test the ID here. So if I put like an ID of minus one, notice we got an error because negative is not allowed. Our code, we test that out. If I enter a non-native number and I remember like a P, right? Same thing, I got an invalid ID or auto-arranged number. Okay, so we use that code here inside the page. Okay, this piece of code here actually does that for you. Is it set, if it's not set, then we get an error. It is set, but it's an invalid because it's not an integer, then error. It was an integer but it's not greater than one and error, so we have two ways to do it. Okay, so I hope this is helpful and understanding how this works. So normally, this is just one way to do it, right? So normally you're not gonna put all your controls here. You don't need to do this, but I'll show you that quickly. So normally you put a single page here. I'll call it maybe just a route, okay? The route goes here and I will switch the get here. The get of the route, okay? If the route is going to, let's just say the home and I will load an object. So over here in the controller, I would have another folder here. Oops, I have a decision really quickly. So I have the controller here and set a controller. You're gonna have a new class for example, you call it home controller, okay? And then I have another one here for page controller. Inside the page controller, you have functions like this. Public function load page, right? You have a public function delete page and so on. And then so on. And then inside the home controller, again, public function load home page and so forth, okay? So you have those in there and then then your route over here. If it's home, then you're gonna create an object. So you can do up here if you want right away. Home is equal to home object, home controller. And then page is equal to no page controller. Oops, right? If it's home, then I'm gonna go to the home controller, load the page, load the home page, right? And then if it's a delete, then I go to the delete page. So page delete. And then if it's a page, then you go and load the page. So that's how usually you do it. And then, you know, your index page will load the route and then you just load the content here. So your URL usually doesn't change. We're kind of similar to how we generate the error and then, you know, just a little content like this, like the index, the page has error. But over here, I saw the home page. If I do something like custom error, it's still the index page, but I have different content here. Okay. And then so when you do this way, all your controllers will be inside this controller file. Outside here, you might have just one main index file or main route file that control all that navigates all the routes to their correct places. All right. So we just did, you know, mainly just review pages and things like that. You can also do register the user. We did not verify the user is indeed a value user or not. But usually we do that thing you can have so that the page can have an edit mode or they can delete pages and things like that. You did that before with the guestbook, same idea. Okay. That's all I have. So thank you guys. So the homework assignment will be similar to what we just did. The logic is still the same. The way the author did in the book is a little different. But you are more than welcome to do exactly what's in the book or if you modify it to do it this way. That's entirely up to you. One thing that I mentioned in my slides and my notes over here, when you get there is that in the book or the exercise, ask you to use. So this part here, I turn that up. Okay. I'm not gonna do that part here. So one of the pages actually uses the HTML quick form format. So when you get there to that page, just don't use it. Just convert that into regular HTML, a login form and do it that way, okay? If you get stuck, just let me know. Just a lot of errors with this quick form. All right, thank you guys. So have a good weekend and I will see you all next week. Have a good weekend. Thank you. Good night.