Чеканите мой вьювер.
<?php
class View {
protected $_block = array();
private static $_instance = FALSE;
protected $_data = array();
private function __construct(){
}
public function GetInstance(){
if (self::$_instance === false) {
self::$_instance = new View;
}
return self::$_instance;
}
public function SetViewClassFile($file){
$file = 'application/view/'.$file.'.php';
if(file_exists($file)){
require_once($file);
}
else {
throw new Exception('���� '.$name.' �� ������');
}
}
public function Set($name,$data){
$this->_block[$name] = $data;
}
public function __call($name,$val){
if(array_key_exists($name,$this->_block)){
$this->setViewClassFile($name);
return new $name($this->_block[$name]);
}
}
public function __set($name,$value){
$this->_block[$name] = $value;
}
public function __get($name){
return $this->_block[$name];
}
public function display() {
$this->render();
}
public function render() {
require_once('application/templates/index.tpl');
}
}
?>
<?php
class main {
public $data;
public function __construct($data){
$this->data = $data;
$this->SetFile();
}
public function SetFile(){
include('Application/templates/main.tpl');
}
}
?>
<?php
include('view.php');
$view = View::GetInstance();
$main[] = array('title'=>'Main Block','text'=>'Text Main Block');
$main[] = array('title'=>'Main Block2','text'=>'Text Main Block2');
$view->main = $main;
$view->display();
?>