Cześć,
w poprzednim temacie spytałem sie Was o naukę wzorca MVC. Poczytałem o nim i zrozumiałem część teoretyczną a dzisiaj zabrałem się za część praktyczną. Napisałem prostą (nawet nie ;p) stronę korzystająć z tego wzorca i prosił bym Was o wypowiedzenie się czy dobrze zrozumiałem istotę MVC.
index.php
<?php
require_once('controller.php');
$cont = new Controller(); //displaing page
?>
controller.php
<?php
require_once('model.php');
require_once('view.php');
class Controller
{
private $model;
private $view;
public function __construct()
{
$this -> model = new Model();
$this -> view = new View($this -> model -> getVar1(), $this -> model -> getVar2());
$this -> view -> displayView();
}
}
?>
model.php
<?php
class Model
{
private $var1;
private $var2;
public function __construct()
{
$this -> generateStuff(); //it's will changed in the future ;p
}
public getVar1()
{ return $this -> var1; }
public getVar2()
{ return $this -> var2; }
private generateStuff()
{
/*
Here you can implement code to fetch data from file, web page, database or soo.
*/
$this -> var1 = "This is some title"; //like i said you can implement here other stuff
$this -> var2 = "Hello, greetings from function in model ;)";
}
}
?>
view.php
<?php
class Model
{
public $var1;
public $var2;
public function __construct($VAR1, $VAR2)
{
$this -> var1 = $VAR1;
$this -> var2 = $VAR2;
$this -> displayView();
}
private function displayView()
{
echo <<<START
<html>
<head>
<title>{$this -> var1}</title>
</head>
<body>
<h1>{$this -> var2}</h1>
</body>
</html>
START;
}
}
?>
Mam też kilka pytań. Czy nowy widok musi się równać nowemu plikowi (np. onas.php - jako widok)?
Czy może być taka sytuacja gdzie będą dwa modele?