What us MVC (Model View Controller)?
A free video tutorial from Brad Traversy
Full Stack Web Developer & Instructor at Traversy Media
4.7 instructor rating • 14 courses • 251,983 students
Learn more from the full courseObject Oriented PHP & MVC
Build a custom object oriented PHP MVC framework and then build an application with it
06:39:40 of on-demand video • Updated November 2017
- Build a custom MVC Framework from absolute scratch
- Build an application using your custom framework
- Create a custom PDO class to handle database interactions
- Complete user authentication using OOP & PDO
- Deploy your custom PHP application
English [Auto] It guys so I briefly want to touch on what MVC is or model view controller. This is a learn by example of course but I still want to just address the fundamental concepts. All right. So MVC stands from all of your controller and it's a software architectural design pattern and it's one of the most common patterns used. It's definitely not specific to just P you'll find MVC in many languages and frameworks it's very popular and C-Sharp and HSP dot net. Ruby on Rails is another really popular MVC framework. And then you have established PDP frameworks like where a valid code igniter that used concepts from MVC as well. Right now the main purpose is to separate functionality and in some of the purposes of your application into three different areas. And this promotes organization among other advantages. All right so let's start with the model. All right. So the model is used to deal with data and data related logic. So select statements to fetch data inserts updates deletes and so on. It also communicates with the controller. The controller often need something from the database so it will call in the model to do that to make the query and all that. Now in our case we're going to do in our project and our framework is we're going to build a database library class that the model will connect to. That way we can we can use PTO and we can fetch data and in certain all that through the model. All right then we have the view the views the part that the the the user sees in the application. So it's the user interface. It usually consists of each team own CSX. Sometimes they'll be a template engine used a peach can be used as its own template engine. It can also crew communicate with the controller. The controller takes care of you know loading the view and it can also pass data into the view. Usually that data is requested from the model because it comes from the database and we know that the model takes care of anything to do with the database. All right now the controller is just that it's like a traffic controller. It takes requests and input from things like the R-AL also formed data. The process forms you can submit to the controller. And then what it does is it'll fetch data from the model if needed. It'll add data through the model to the database if needed or it will just load of view. OK so here's a simple diagram representing the workflow of MVC. So basically we have a user and a browser. They make some kind of request going to a specific u r l and there'll be some kind of router or bootstrap program. What we we're going to do is we're going to have a base controller that's going to handle taking out a parameter from the R L and turning that into a controller method that needs to be called and we'll be able to also pass parameters through the u r l and we're going to do this with the help of something called Daut h t access which will get into later. All right but then the controller if needed will communicate with the model if it needs to fetch from the database or it needs to insert something or added something and then it will load the view it can pass data to the view and then you know people can click on links in the view which can go back to the controller and then go back to the browser. OK. So this is a basic workflow of an MVC type application. And it can get a little confusing because each platform like like what say Ruby on Rails. The MVC the way that MVC works may be a little different than let's say Pietsch piece code igniter framework it's some frameworks used just certain aspects some are full on hard core MVC sometimes NBC is optional like if you're using know an express so it can get a little confusing. But hopefully this course clears some things up as we're building you know our framework from scratch that's going to use model view controller. All right so that's it guys. And the next video I want to start to talk a little bit about PTO which is the PSP extension we're going to be using to communicate with the database.