What is Model View Controller ? MVC framework



What is MVC ?

MVC stands for Model View Controller. It is a structure on how most of the frameworks work.

So let us study the working of MVC.

  • Model
  • View
  • Controller
What is a Model ?

Model is the place where all the database structure, relationships,(business logic) are written. We use the Model to retrieve/fetch and insert/save data into the database. 

What is a View?

View is the Output that the user will be seeing in the browser. The View is basically the HTML code. 

What is a Controller ?

Controller is the place where all the database interactions are done. Any calculations, functions, or functionality is written the controller.

We studied that Models are used to fetch and insert data, Is that the same function of the controller? 

The answer is No. Model will have the database structure and in the controller we use the model to retrieve and insert data from and to the database.

Now let's discuss with an example

Most of the frameworks run on the same web address i.e. localhost:8000

So basically, when you search for a url like localhost:8000/products , In the file where you write your routes(file names are different for different frameworks like routes.php for Codeigniter, web.php for Laravel, etc) the control goes and searches for the route "/products" and then the control will go to the controller's function corresponding to that route. 

For Example:


In the above example, the control will go to the controller named ProductController and go to the function named index().

Now inside the ProductController's index()

public function index()
return view('home');
The above code is returning a view that is a .html or .php file. In the above example the file name is home.php/home.html 

© Copyright - 2018 - 2023 | All rights reserved at Funda of Web IT