text = 'Hello world!';
}
}
class View {
private $model;
private $controller;
public function __construct(Controller $controller, Model $model) {
$this->controller = $controller;
$this->model = $model;
}
public function output() {
return '
' . $this->model->text .'
';
}
}
class Controller {
private $model;
public function __construct(Model $model) {
$this->model = $model;
}
}
//initiate the triad
$model = new Model();
//It is important that the controller and the view share the model
$controller = new Controller($model);
$view = new View($controller, $model);
echo $view->output();
echo "
";
echo "The above output is generated by the code below:
";
highlight_file( __FILE__ );
?>