Chciałem Wam pokazać mój sposób na relację Model <-> Widok. Nie jest najtrudniejsza, ale działa jak powinna.
Oczywiście jest to tylko prototyp i nie ma związku z tym, z czym korzystam, tworząc swoje strony www.
<? // Singleton Interface Interface Singleton { public function singleton(); } // Observ Interface Interface Observ { public function Update(); } // ObState Interface Interface ObState { public function notify(); public function register($what); } // View Class class View implements Singleton, Observ { public function singleton() { if (self::$singleton == null) self::$singleton = new self(); return self::$singleton; } public function update() { self::$data = $aParametrs[0]; } public function __get($a) { return self::$data -> $a; } } // Model Class class Model implements Singleton, ObState { public $data; public function singleton() { if (self::$singleton == null) self::$singleton = new self(); return self::$singleton; } public function register($what) { self::$observs[] = $what; } public function notify() { foreach (self::$observs as $observ) { $observ -> update($this -> data); } } } // SomeModel Class Class SomeModel extends Model { public function doSomethink() { $this -> data -> shit = 'matix'; $this -> data -> dbResult = 'select * from blabla'; #$this -> data -> jeszcze -> jeden -> shit = 'ble'; $this -> notify(); } } //SomeView Class Class SomeView extends View { public function getSomeVars() { } } // Running ... $view = View::singleton(); $model = Model::singleton(); $model -> register($view); $sm = new SomeModel; $sm -> doSomethink(); $sv = new SomeView; $sv -> getSomeVars(); ?>
Pomijam tutaj Kontroller, bo on mnie tutaj nie interesuje.
Myślicie, że taka implementacja w frameworku mogłaby być ciekawa?
Plusem tego jest to, że dane są przechowywane w taki sposób:
<?php $this -> data -> NAZWA = 'wartosc'; $this -> data -> imie = 'mateusz'; $this -> data -> wiek = '15 lat'; $this -> data -> adresy -> domowe -> wszystkich -> uzytkownikow -> serwisu -> o -> dragonballu; ?>
Dane zostają następnie przesłane do Widoku poprzez Wzorzec Oberwator, i są dostępne z każdego miejsca.
W widoku odwoływanie się do danych jest w ten sam sposób, tyko pomijając '- > data ->', czyli:
<?php ?>
Co wy na to
