Model - View - Controller

In this post I want to talk about MVC architecture. When working with frameworks you can see that there are lots of frameworks which are using this pattern.
In this post I want to talk about MVC architecture.
When working with frameworks you can see that there are lots of frameworks which are using this pattern.
What is MVC?
MVC is a software architecture pattern. There are three different types of files. One is called Model, another one is called Controller, and the last one is View. Our projects have two parts. One part is our database, and the other is the view or user interface. The standard way of using databases is that the user cannot directly work with the database. So, he has to send his request to another class other than the view and that class will send our requests to the database.
Yii is a php framework which uses this pattern. There are three folders in any Yii application. Model, View, and Controller.
What are Models?
Models are classes built based on our tables in our database. So, every table has its own model. As you have seen in the previous posts, when fetching records from a table or inserting one into a table, instead of working with the original table, we create an object of their class (our table's model) and we use that to work with the database. Our models have all attributes of the table they were built from and they can also have some functions which we can use to do several things. As an example we can have a save function, or an update function, and lots of other useful functions.
What are Controllers?
As you can guess from their name, these classes control the user's request. They have functions that based on the thing you want to do (for example save, create, delete, view, list and etc.) a specific function of this class will be called. So, we send our requests to one of these functions, the function will handle whatever it is that we want to do. It will also redirect us to the proper view for that specific job.
What are Views?
Every action must have a view file. View is what the user can see. In web, views are our HTML, php, CSS and javascript files we use to show a page, a record or a list of records.
When we send a request from the view, it will be sent to our controller and from there it will be sent to the needed models and then the results will be sent to the controller The controller can process the results, then they would be sent to the proper view. So a user cannot directly connect to the database and also the database cannot send results directly to the use.