What is Model View Controller (MVC) Framework publisher image
Lamai Institute

What is Model View Controller (MVC) Framework

Php MVC Web framework

What is PHP MVC framework?

PHP MVC is an application design pattern that separates the application data and business logic (model) from the presentation (view). MVC stands for Model, View & Controller.

The controller mediates between the models and views.

Think of the MVC design pattern as a car and the driver.

The car has the windscreens (view) which the driver (controller) uses to monitor traffic ahead then speed or brake (model) depending on what he sees ahead.

What is a PHP framework?

A PHP framework is a platform or you can say that tools which is for creating PHP web applications. It contains libraries with pre-packaged functions and classes and elements for software design pattern.

Framework follow the MVC (Model View Controller) architecture, So PHP frameworks help to rapid application development (RAD). And saves time to build more stable applications, and reduce the repetitive coding for developers.

PHP framework also streamline the development of web applications, by providing basic and standard structure to build web applications. Using framework you can developed more secure web application even you don’t’ have good skilled, because frameworks developed by highly experienced and expert developers. So that just you should know how to use framework and be more productive.

Why use PHP MVC Framework?

  • Speed up development process
  • Reuse code across similar projects
  • There are lots of pre-build module for achieving similar kind of task, just need to download and use, so that you can focus on your actual project development.
  • Stability and robust coding done in framework is one of the great reason to choose framework.
  • Simplicity, use of MVC
  • Great security and MySQL injection provided
  • CSRF token provided by all most all frameworks
  • Cross-site Scripting (XSS), security can be enabled quickly.
  • There are lots of PHP framework available to choose any as well open source, so that is one of the reason to choose framework.
  • large support teams, and their forums/communities that allow you to interact with other developers who use the same framework

When to use a PHP framework ?

There are no direct answer of this question, because it’s depend on who is using and what kind of project have.

If you are the PHP beginners then, initially, you should not use PHP framework, because reason mention below.

  • You will not able to realised your coding is optimised or not, and in future you will feel your-self as poor developer, so my suggestion at least you should work some time on Core PHP, so that your basic will be good.
  • Framework having large libraries so it will have also difficult to understand, how is it’s working if your basic isn’t good.
  • You will little bit confused when, you got huge kind of PHP term at once, e.g. namespace, model, view, migration, seeds etc.
  • Major thing, you are not able to decide which framework suites for this project.

 

MVC stands for "Model view And Controller".

The main aim of MVC Architecture is to separate the Business logic & Application data from the USER interface.

Different types of Architectures are available. These are 3-tier Architecture, N-tier Architecture, MVC Architecture, etc.

The main advantage of Architecture is Reusability, Security and Increasing the performance of Application.

Model: Database operation such as fetch data or update data etc.

View: End-user GUI through which user can interact with system, i.e., HTML, CSS.

Controller: Contain Business logic and provide a link between model and view.

Let's understand this MVC concept in detail:

Model

This part is concerned with the business logic and the application data. It can be used to perform data validations, process data and store it. The data can come from;

  • flat file
  • database
  • XML document
  • Other valid data sources.

The Model object knows all about all the data that need to be displayed, represents the application data and business rules that govern to an update of data and is not aware about the presentation of data and how the data will be display to the browser.

View

This part deals with presenting the data to the user. This is usually in form of HTML pages. 

  • The View represents the presentation of the application.
  • View object refers to the model remains same if there are any modifications in the Business logic.
  • In other words, we can say that it is the responsibility of view to maintain consistency in its presentation and the model changes.

Controller

This is the part deals with the users’ requests for resources from the server.

As an example, when the users requests for the URL …/index.php?products=list, the controller will load the products model to retrieve the products data then output the results in the list view.

In a nutshell, the controller links the models and views together depending on the requested resources.

  • Whenever the user sends a request for something, it always goes through Controller.
  • A controller is responsible for intercepting the request from view and passes to the model for appropriate action.
  • After the action has been taken on the data, the controller is responsible for directly passes the appropriate view to the user.
  • In graphical user interfaces, controller and view work very closely together.

Types of PHP MVC framework

 Selecting the best PHP framework is a challenge.

You don’t have to write your own framework to benefit from the advantages of MVC.

You should only attempt to create your own MVC related application design for understanding how MVC frameworks work.

Once you are comfortable with the way MVC frameworks work, you should move on to the mature and already tested frameworks. 

  1. Codeigniter
  2. Kohana
  3. CakePHP
  4. Zend
  5. Laravel

Summary

  • A framework is a set of libraries that provide partial implementation of common tasks.
  • PHP has a number of open source mature and tested MVC frameworks.
  • A good development approach separates the data from the presentation and encourages the use of single entry point into an application.
  • Traditional PHP applications that follow application design best practices can be ported to MVC frameworks with minimal modifications.