MVC Architecture

Programmers who already know about the MVC architecture can skip this post and move to installation.

Well MVC stands for Model, View and Controller.

Its work is to divide the code into specific responsibilities.

Here’s a fun fact: you’re looking at a MVC right now.

This web page is a perfect example of the MVC structure. Here, the HTML structure of this web page is the Model, the CSS stylesheets that control its appearance are the View, and the browser that you use to interact with the web page is the Controller.

Let’s look at this in a little more detail:

Consider your typical procedural code. It looks something like this

But MVC doesn’t accept that.

It expects you to write the logic, database connection, api calls and HTML into specific responsibilities.

In MVC there is specific class for database connection, specific class for writing logic and specific view files for writing HTML. We will not put all the things in one file.

 

Image credit: www.joomlavision.com
Image credit: www.joomlavision.com

Models

Models means knowledge. It keeps all the knowledge of your app.

Like it knows which database table to connect, what should be the rules for form submission and so on.

 

Views

Views are the visual representation. You write your HTML stuff in the view files.

MVC don’t want you to create variables directly in view.

 

Controller

Controller is the bridge between user and system. It is application’s Logic.

Controller receives requests and return responses.

 

Well I guess you must have got a basic idea about the MVC architecture. You will get to know more about it as you work on it.

So lets do some exciting stuff. Lets install laravel.

Share this article: