MVC:
The MVC pattern separates an application in 3 modules: Model, View and Controller:
MODEL:
MVC Structure:
<?php
include_once ("controller/controller.php");
$controller = new Controller();
$controller->invoke();
?>
Our Controller class has only one function and the constructor. The constructor instantiate a model class and when a request is done, the controller decide which data is required from the model. Then it calls the model class to retrieve the data. After that it calls the corresponding passing the data coming from the model. The code is extremely simple. Note that the controller does not know anything about the database or about how the page is generated.
<?php
include_once("model/model.php");
class controller
{
public $model;
public function __constructor
{
$this -> model = new model();
}
public function invoke() {
if(isset(!$_GET['book']))
{
}
else {
}
}
}
?>
The MVC pattern separates an application in 3 modules: Model, View and Controller:
MODEL:
- The model is responsible to manage the data; it stores and retrieves entities used by an application, usually from a database, and contains the logic implemented by the application.
- The view (presentation) is responsible to display the data provided by the model in a specific format. It has a similar usage with the template modules.
- The controller handles the model and view layers to work together. The controller receives a request from the client, invoke the model to perform the requested operations and send the data to the View. The view format the data to be presented to the user, in a web application as an html output
MVC Structure:
Controller
The controller is the first thing which takes a request, parse it, initialize and invoke the model and takes the model response and send it to the presentation layer. It’s practically the liant between the Model and the View, a small framework where Model and View are plugged in. In our naive php implementation the controller is implemented by only one class, named unexpectedly controller. The application entry point will be index.php. The index php file will delegate all the requests to the controller:<?php
include_once ("controller/controller.php");
$controller = new Controller();
$controller->invoke();
?>
Our Controller class has only one function and the constructor. The constructor instantiate a model class and when a request is done, the controller decide which data is required from the model. Then it calls the model class to retrieve the data. After that it calls the corresponding passing the data coming from the model. The code is extremely simple. Note that the controller does not know anything about the database or about how the page is generated.
<?php
include_once("model/model.php");
class controller
{
public $model;
public function __constructor
{
$this -> model = new model();
}
public function invoke() {
if(isset(!$_GET['book']))
{
}
else {
}
}
}
?>
No comments:
Post a Comment