Nie chodzi o to, że boję się pokazać ale sporo tego jest. Zatem do dzieła:
indexController
class indexController extends BaseController {
public function index() {
$url = $this->registry->settings->getSettings('mainurl');
$this->registry->view->url = $url; //$this->registry->view jest obiektem klasy View
//wywolanie widoku
$this->registry->view->show('main', array('top', 'middle', 'footer'));
}
}
View
class View {
private $_registry;
private $_vars = array(); private $_path;
public function __construct($registry) {
$this->_registry = $registry;
}
public function __set($index, $value) {
$this->_vars[$index] = $value;
}
//pokazuje okreslony widok
public function show
($view, $view_modules = array()) { // Ładowanie zmiennych do widoku
if (!class_exists($view)) {
//TODO obsluzyc jesli brak widoku
throw new Exception ('Nie można wczytać widoku: '. $view);
}
foreach ($view_modules as $value) {
if (!is_callable("{$view}::{$value}")) {
//TODO obsluzyc niepoprawny modul widoku
throw new Exception('Nie można wczytać modułu wiodku: '.$value.' w widoku: '.$view);
} else {
call_user_func("{$view}::{$value}", $this->_vars);
}
}
}
}
Widok main:
class main {
private function __construct() {
}
public static function top
($view) { echo $view['url']; //pokazuje prawidlowy url } else {
}
//echo var_dump($view);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>new_file</title>
<meta name="description" content="" />
<meta name="author" content="Maciek" />
<meta name="viewport" content="width=device-width; initial-scale=1.0" />
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="stylesheet" type="text/css" href="'.$view['url'].'/css/style.css" /> <!--zwraca, że jest undefined index-->
</head>
<body>
top<hr><br /><br/>
';
}
public static function middle
($view) { <a href="'.$view['url'].'/register">Zarejestruj się</a>';
}
public static function footer
($view) { <br /><br /><hr>footer
</body>
</html>
';
}
}
Co ciekawe tylko, w metodzie "top", zwraca ten błąd.