Model View Controller Structure Tutorial

Model View Controller Structure Tutorial

Model View Controller Structure Tutorial

Model View Controller Structure (MVC): This is a software design pattern. There are many more such design patterns. Following these patterns when coding makes the code look clearer and even easier to maintain (code refactoring) later. For example, when coding with raw PHP, we usually write HTML, logic, database access code, queries, etc. on the same page. It is very difficult for another developer to work on this code later. In fact, you will not understand when you see this code later, especially when there will be big projects and scripts will be much bigger. See the code below as no design pattern has been followed here.

 

<?php
    include "config.php";
    include "subject.php";
    mysql_connect($hostname, $username, $password);
    mysql_select_db($database);
?>
<?php include "top_header.php"; ?>
    <h1>News Page</h1>
    <?php
    $sql_f = "SELECT * FROM news_data";
    $result_data = mysql_query($sql_f);
?>
<table>
    <?php
        while ($row_news = mysql_fetch_assoc($result_data)) {
    ?>
    <tr>
        <td><?php echo $row_news['news_title']; ?></td>
        <td><?php echo $row_news['news_details']; ?></td>
    </tr>
    <?php
    }
    ?>
</table>
<?php include "bot_footer.php"; ?>

 

Writing the code in this way makes it very difficult to edit or update the code later. The model view controller design pattern has solved this problem. This MVC Structure allows you to write codes in 3 parts, but it will work all at once, just as writing codes together will work.

Model

View

Controller

Model: 

Suppose you are creating an application by writing code in CodeIgniter, out of all the codes in this application the model part will contain only those codes (or you can say logics or functions) by which you will insert, delete, update, etc. in the database. That means the model part will represent your data structure. These logics are called business logic.

View:

Here are the codes by which the user will view a page. This means that it is a normal web page or you can say HTML page. CodeIgniter can also have a part of a page here such as page header, footer, RSS page etc.

Controller:

The controller will contain all the codes by which the logic of the model and the view will communicate with each other. This means that the logics of how the model and the view will work are written here.

The CodeIgniter framework works on the basis of MVC i.e. model view controller structure i.e. code is written here in this way.


push-MVC vs. pull-MVC (web application)

MVC (Model View Controller) is a software design pattern. However, usually, those of us who work with web applications work with push-MVC. Because most frameworks follow this architecture.

push-MVC: This method is processed using the method/action (usually recognizing the action from the URL or routing) and then pushing the data view from the controller (View). The architecture of push-MVC is action-based. Example: Symfony, CodeIgniter These frameworks use this architecture.

pull-MVC: In this method, from the view layer it is decided from which controller to bring data, from the controller it is decided from which model the data will come. If necessary, it can be decided from the view whether to bring data from multiple controllers (meaning data can be fetched from multiple controllers). Pulls data hence the name pull-MVC. The Joomla Framework (framework.joomla.org) uses this architecture. Its architecture is component-based

However, some frameworks use both push and pull such as Zend, Wii Ii, etc.

 

TagModel View Controller Structure Tutorial, what is mvc framework, what is mvc medical, what is mvc stand for, what is mvc architecture, what is mcv in blood test, what is mvc application, what is mvc and mvvm,  model view controller, model view controller example, model view controller design pattern, model view controller explained, model view controller pattern, model view controller php, model view controller laravel, model view controller architecture, model view controller python, model view controller javascript, model view controller architecture pattern, model view controller alternatives, model view controller angular, model view controller application, the model view controller, mvc php project, mvc php project, mvc laravel pdf, mvc laravel php, learn mvc, what mvc, mvc pattern, learn mvc pattern, basic mvc pattern, mvc pattern basic, learn mvc basic pattern, what is basic mvc pattern, only learn 24, onlylearn24

Thank You...................