A new, object-oriented, better vesion of μForum
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
995 B

  1. <?php
  2. require_once('./inc/askModel.class.php');
  3. abstract class Controller extends AskModel {
  4. protected $views = array();
  5. protected $db;
  6. abstract public function loadDefault(); //domyślna metoda
  7. public function __call($m, $arg)
  8. {
  9. if(method_exists($this, $m))
  10. $this->$m($arg);
  11. else
  12. $this->forward('index.php');
  13. }
  14. public function __construct(&$db)
  15. {
  16. $this->db = $db;
  17. }
  18. public function forward($address)
  19. {
  20. header('Location: ' . $address);
  21. }
  22. public function loadView($view)
  23. {
  24. if (file_exists('./inc/views/'.$view.'.class.php') && !array_key_exists($view, $this->views))
  25. {
  26. require_once('./inc/views/'.$view.'.class.php');
  27. $this->views[$view] = new $view($this->db);
  28. }
  29. else
  30. {
  31. throw new Exception('Could not load selected view: '.$view);
  32. }
  33. }
  34. public function getView($view)
  35. {
  36. if (array_key_exists($view, $this->views))
  37. return $this->views[$view];
  38. else
  39. throw new Exception('Could not get selected view: '.$widok);
  40. }
  41. }
  42. ?>