Learn

MVC (Model View Controller)

MVC Model View Controller
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

MVC Model View Controller

What is Model View Controller (M.V.C)?

MVC abbreviation of Model View Controller is also known as an architectural design pattern that we use to design our applications in a better and professional way. With the help of MVC, we can control every part of our project more efficiently and professionally. There is no specific tool to develop an application in MVC, you can use any development interface like adobe Dreamweaver, eclipse for PHP etc. So you don’t need to worry about to switching from one development interface to other. You can use any one which suits you and it won’t affect your application.Before starts working in MVC, you must have a knowledge of OOP (Object Oriented Programming). I will explain a little bit about Object Oriented Programming with some examples.

“One thing to keep in mind everything is difficult until you properly learn it and implement it.”

No matter what language you are using or what type of application you are building, MVC is the best solution to adopt for good and professional results. MVC is widely used by a lot of programming languages like PHP, asp.net, java, C++ etc. But as a PHP programmer I will guide you how to use MVC structure in PHP.

Before going deeper into MVC, you need to understand the execution process of MVC and the way it works. Let’s explore the definition of MVC first then we will move to the execution process.

Definition and explanation of MVC

M stands for Models: Models play a very important role in an application because it interacts with our database to create-read-update-delete the records, classes, objects. Models don’t have any concern with the layout structure of your application or with anything else. It only uses to define objects, classes, function.

V stands for Views: View is also known as front end of your application where the user can see and interacts with different elements shown in your application such as a button, links, logos etc.

C stands for Controller: Controller plays a role of the bridge between views and models. Controller used to pass the instruction from view to model and give the results back to view according to the instructions.

Structure of MVC:

The structure of MVC is very simple we just need to create some folders and files to start working with.

Let create a simple structure of MVC. This is just an idea and the way I am creating my application, but you guys can do it in your way.

mvc_image_1

In this picture I simply create a project folder and in that folder I create some subfolders. Let’s see which files I am going to keep in these folders.

Under Project Folder, I create subfolders config, controllers, libs, models, public, upload, views

Config Folder: In config folder, we will keep some configuration files like paths, project settings etc. which we will use in our project at many places.

Controllers Folder: As like its name controller folder will contain all the controller files that we use to define our controllers which help us in building a bridge between views and models.

Libs Folder: In Libs folder, I will keep some important files like sessions, user rights, database etc. In short I will keep all the library files in this folder.

Models Folder: Model is the folder where I will keep my model files. These files will be used to do some intelligent work like our application logics, database connectivity, creating, reading, updating and deleting the records.

Public Folder: In this folder, I will keep my user interface supporting files like CSS, fonts, js, images, etc. Everything that we are going to use in user interface design, we will keep them in this folder.

Upload: We will use this folder to keep our files, images etc. which we upload using our application code dynamically not statically.

Views: At last we will create a view folder. This folder contains all the files which are related to user interface like our application design etc.

We will study Object Oriented Programming in next article. Any questions, suggestions, comments feel free to write.


  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Most Popular

To Top