oktatas:programozas:php:php_mvc
< PHP
PHP MVC
Egy egyszerű példa
- index.php
<?php
class Model {
public $name;
public $age;
public function __construct(){
$this->name = "Nagy József";
$this->age = 25;
}
}
class Controller {
private $model;
public function __construct(Model $model){
$this->model = $model;
}
}
class View {
private $model;
private $controller;
public function __construct(Controller $controller, Model $model){
$this->controller = $controller;
$this->model = $model;
}
public function getName(){
return "<h1>" . $this->model->name ."</h1>";
}
public function getAge(){
return "<h1>" . $this->model->age ."</h1>";
}
}
$model = new Model();
$controller = new Controller($model);
$view = new View($controller, $model);
echo $view->getName();
?>
oktatas/programozas/php/php_mvc.txt · Utolsó módosítás: 2019/08/22 10:33 szerkesztette: admin