assessmentee.com

Home | Start test | Contact
 

Activerecord | Adapter | Decorator | DependencyInjectionContainer | Facade | Factory | Hydration | Inheritance | Iterator | Mapper | MVC | Observer | Prototype | Proxy | Registry | ServiceLocator | Singleton | Specification | Strategy | TableGateway | ZF1_TableGateway | ZF2_TableGateway |




    <?php
/*
 * Model-View-Controller design pattern
 * Source: http://phpmaster.com/the-mvc-pattern-and-php-1
 */

class Model
{
    public $string;

    public function __construct(){
        $this->string = "The MVC pattern";
    }
}

class View
{
    private $controller;

    public function __construct($controller) {
        $this->controller = $controller;
    }

    public function output(){
        return "<p>" . $this->controller->string . "</p>";
    }
}

class Controller
{
    private $model;
    public $string;

    public function __construct($model) {
        $this->model = $model;
        $this->string = $this->model->string;
    }
}

$model = new Model();
$controller = new Controller($model);
$view = new View($controller);
echo $view->output();

?>

    

Outputs:


The MVC pattern



 

© 2018 assessmentee.com