Skip to main content

[PHP]Conventional v/s Configurable

ravimanephpmysql

Types of MVC: Conventional v/s Configurable




Now a days all the applications are being created using the MVC architecture, as it a most powerful and successful way to develop the application.

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

    Convention Based MVC
    Configuration Based MVC


Types of MVC Architecture

Convention Based MVC


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:

    CakePHP
    Codeigniter
    YUI
    Kohana

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.
Copy
class Product_model extends CI_Model
{
   function __construct()
   {
       parent::__construct();
   }
}


Configuration Based MVC


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:
Copy
<models>
    <packagename>
         <class>Packagename_Modulename_Model</class>
   <packagename>
</packagename></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?

Popular posts from this blog

Draw pyramid shape of stars in PHP using loop structure Write down the code in PHP using loop structure to draw the 3 pyramid shapes of stars as given bellow:

ravimanephpmysql

// problem 01 solution
for($i=5;$i>=1;$i--)
{
echo  str_repeat('*',$i);
echo "<br />";
}

echo "<hr />";

// problem 02 solution

for($i=1;$i<=5;$i++)
{
echo  str_repeat('*',$i);
echo "<br />";
}


echo "<hr />";
// problem 03 solution

$j=1;

for($i=5;$i>=1;$i--)
{
//echo  str_repeat("&nbsp;",$i-1);
echo  str_repeat('*',$j++);
echo "<br />";
}

Google reCAPTCHA with PHP tutorial

Login to your Google account and submit the form. Once submit, Google will provide you following two information. Site keySecret key

Integrate it into your website. To integrate it into your website you need to put it in client side as well as in Server side. In client HTML page you need to integrate this line before <HEAD> tag.
<script src='https://www.google.com/recaptcha/api.js'></script> And to show the widget into your form you need to put this below contact form, comment form etc.
<divclass="g-recaptcha" data-sitekey="== Your site Key =="></div> When the form get submit to Server, this script will send ‘g-recaptcha-response’ as a POST data. You need to verify it in order to see whether user has checked the Captcha or not. Simple comment form with Google reCAPTCH:Index.html <html>
<head>
<title>Google recapcha demo - Codeforgeek</title>
<scriptsrc='https://www.google.com/recaptcha/api.js'&g…

Simple Laravel CRUD with Resource Controllers

Creating, reading, updating, and deleting resources is used in pretty much every application. Laravel helps make the process easy using resource controllers. Resource Controllers can make life much easier and takes advantage of some cool Laravel routing techniques. Today, we'll go through the steps necessary to get a fully functioning CRUD application using resource controllers. For this tutorial, we will go through the process of having an admin panel to create, read, update, and delete (CRUD) a resource. Let's use nerds as our example. We will also make use of Eloquent ORM. This tutorial will walk us through: * Setting up the database and models * Creating the resource controller and its routes * Creating the necessary views * Explaining each method in a resource controller Table of ContentsGetting our Database ReadyEloquent Model for the NerdsCreating the ControllerSetting Up the RoutesThe ViewsMaking It All Work TogetherConclusion To get started, we will need the controll…