Files
uf2/inc/controller.class.php

53 lines
995 B
PHP

<?php
require_once('./inc/askModel.class.php');
abstract class Controller extends AskModel {
protected $views = array();
protected $db;
abstract public function loadDefault(); //domyślna metoda
public function __call($m, $arg)
{
if(method_exists($this, $m))
$this->$m($arg);
else
$this->forward('index.php');
}
public function __construct(&$db)
{
$this->db = $db;
}
public function forward($address)
{
header('Location: ' . $address);
}
public function loadView($view)
{
if (file_exists('./inc/views/'.$view.'.class.php') && !array_key_exists($view, $this->views))
{
require_once('./inc/views/'.$view.'.class.php');
$this->views[$view] = new $view($this->db);
}
else
{
throw new Exception('Could not load selected view: '.$view);
}
}
public function getView($view)
{
if (array_key_exists($view, $this->views))
return $this->views[$view];
else
throw new Exception('Could not get selected view: '.$widok);
}
}
?>