Understanding Model View Controller MVC

--

Understanding Model View Controller MVC

Coming from structural and even OOP of PHP, I had a very big problem understanding Routing and all MVC (Model View Controller) and Frameworks.

I first tried Zend, Yii, Codeigniter, and finally Laravel

I was getting the result at Codeigniter but do not understand how it works.

I keep trying but the process of understanding it was difficult, so if you are having the same challenges now, I will guide you.

Model View Controller popularly called MVC is an architectural pattern that helps you separate your applications into 3 layers.

It keeps your logic on a particular phase(Controller), (View)the frontend and makes access to the database only through the Model.

MVC separates the business logic and presentation layer from each other.

Model: This is where you have a connection to your database, you can access the tables from the model. Each table you have to do within your database normally haves its own model. It is the model that will send data to the controller when the controller requires it. And at the same time receives data from the controller when it wants to store it.

The Controller is that part of the application that handles the logic. The controller interprets the mouse and keyboard inputs from the user, informing the model and the view to change as appropriate.

A Controller that processes the functions of the application. It tells the model to update its state(E.g., Saving, deleting, updating). The controller also tells its associated view to change the view’s presentation (For example scrolling a particular document).

A View just like the name sounds is the frontend, what the end-user sees

Now we will explain this with a real-life scenario. If you decide to build an application like e-commerce or you want to go to a shopping mall to buy cookies.

The View is the shelves where those cookies or products you want to buy are kept so that buyers can see them and buy. Just like the application, it is the View that you are seeing that you can view products and decide to buy then add to cart or leave it.

Now when you see an apple and you decide to buy, It is the controller that does the processing, making sure you are not overpaying, making sure we receive what we paid for (validation), and passing it to the cart or bag(Model) to keep(save) it.

So after buying and you put it in your bag(Model) it is stored there or it is saved there.

When you remove it there you are deleting, or updating. That is how MVC works.

Abanobi Chukwuma Godswill

--

--

Chukwuma Godswill Abanobi “Unique”

A full-stack developer that enjoys critical thinking, communication, Problem Solving and consistently contribute to team efforts and organization