Home » Types of MVC: Conventional v/s Configurable
mvc-design-patterns-conventional-vs-configurable
PHP

Types of MVC: Conventional v/s Configurable

Introduction

In the world of software architecture, understanding the various Models-View-Controller (MVC) paradigms is paramount. Today, we delve into “Types of MVC: Conventional vs. Configurable.” This exploration will help you grasp the intricacies of these MVC design patterns, allowing you to make informed decisions when building software applications. Join us on this journey as we navigate the conventional and configurable MVC approaches and discover which one suits your development needs best.

MVC design patterns, Model View Controller, is an application that tends to segregate data access, user interface and business logic. Generally there are two types of MVC: the convention based and the configuration based. In the convention based MVC you need to follow the core system’s instructions to set up your module while in configuration based you will need to specify everything to your module’s configuration file to get started.

In this article we will see comparison of different types of MVC architecture we have, which are as below:

  1. Convention Based MVC
  2. Configuration Based MVC

Convention Based MVC Design Patterns

As the name suggest, in this type of MVC we need to follow some predefined conventions in order to have it in working mode. This conventions are different from frameworks to frameworks. There are numbers of frameworks out there which follows convention based approach. Some of those frameworks are as below:

In this article we will see convention approach of the Codeigniter, we will see what types of convention are be there for creating a new model in Codeigniter.

First convention is storing of file, we need to store files under specific directory in order to treat it as model file. In Codeigniter all model files are stored under application/models/ directory.

Second convention is giving a name to the files. In Codeigniter model file name must be all lowercase.

Third convention is class name convention. In Codeigniter class name is depends on model file name which we have created in above step. Class name must be same as file name except First character in Class name must be uppercase, also model class in Codeigniter must extends the base class which is CI_Model. Let’s take all above cases with example.

In this example we will create a new model (product) from scratch.

Very first you need to create your model file under application/models/, in this case it would be /application/models/product_model.php

Now we need to define a class in that file. Based on our file name class name would be Product_model which will extend the base class CI_Model. So basic code of this class would be same as below code block.

class Product_model extends CI_Model
{
   function __construct()
   {
       parent::__construct();
   }
}

Configuration Based MVC Design Patterns

Unlike Conventional based MVC, in Configuration based MVC we have full control over file name and class name we use. We can explicitly define which files to load for particular model and which class to find from that file.

Magento is the best example of Configuration based MVC architecture. In Magento each module have its own config.xml file. In this file all the configuration of that particular module, like which files to check, which class to load, etc. Magento is the best example of Configuration based MVC architecture.

In Magento if we want to use custom Model in our module then we will need to add some code in config.xml file to instruct Magento about the class name to search for. Please check below example for the same:

<models>
    <packagename>
         <class>Packagename_Modulename_Model</class>
   <packagename>
</models>

So these are my thoughts on Different types of MVC architecture we can have with PHP. Hey guys do you have any other approach to create an MVC architecture?

Conclusion

In this exploration of MVC design patterns, we’ve delved into the intriguing world of “Conventional vs. Configurable” paradigms. Understanding the nuances and advantages of each approach can be a game-changer in software architecture and development. Whether you’re a seasoned developer or just beginning your journey into MVC, this guide has offered you insights into the choices that can shape your software projects.

As you continue your exploration of MVC design patterns and their applications, consider websites like Javatpoint.

With a solid grasp of these design patterns, you’ll be better equipped to create efficient and maintainable software solutions, making your development journey a successful one.

Add Comment

Click here to post a comment

58 − = 50