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.

59 lines
1.2 KiB

  1. <?php
  2. /**
  3. * @package uForum2
  4. * @file inc/controller.class.php
  5. * @copyright 2007-2015 (c) PioDer
  6. * @link http://www.pioder.pl/
  7. * @license see LICENSE.txt
  8. **/
  9. require_once('./inc/askModel.class.php');
  10. require_once('./inc/view.class.php');
  11. abstract class Controller extends AskModel {
  12. protected $views = array();
  13. protected $db;
  14. abstract public function loadDefault(); //domyślna metoda
  15. public function __call($m, $arg)
  16. {
  17. if(method_exists($this, $m))
  18. $this->$m($arg);
  19. else
  20. $this->forward('index.php');
  21. }
  22. public function __construct(&$db)
  23. {
  24. $this->db = $db;
  25. }
  26. public function forward($address)
  27. {
  28. header('Location: ' . $address);
  29. }
  30. public function loadView($view)
  31. {
  32. if (file_exists('./inc/views/'.$view.'.class.php') && !array_key_exists($view, $this->views))
  33. {
  34. require_once('./inc/views/'.$view.'.class.php');
  35. $this->views[$view] = new $view($this->db);
  36. }
  37. else
  38. {
  39. throw new Exception('Could not load selected view: '.$view);
  40. }
  41. }
  42. public function getView($view)
  43. {
  44. if (array_key_exists($view, $this->views))
  45. return $this->views[$view];
  46. else
  47. throw new Exception('Could not get selected view: '.$widok);
  48. }
  49. }
  50. ?>