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.

61 lines
1.3 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage app
  7. * @since 2010-02-25
  8. */
  9. abstract class Action
  10. {
  11. protected $template;
  12. /**
  13. * @var PHPView
  14. */
  15. protected $view;
  16. public function __construct()
  17. {
  18. $this->view = FrontController::getInstance()->getView();
  19. $this->extractParams();
  20. $this->execute();
  21. }
  22. protected function extractParams()
  23. {
  24. foreach (Env::getParam() as $name => $value) {
  25. if (is_string($name)) {
  26. $this->$name = $value;
  27. }
  28. }
  29. }
  30. abstract protected function execute();
  31. /**
  32. * Redirect
  33. *
  34. * @param mixed $url
  35. */
  36. protected function redirect($url = null)
  37. {
  38. header('Location: ' . (($url) ? $url : Env::getRequestUri()));
  39. exit();
  40. }
  41. protected function getTemplate()
  42. {
  43. $class = get_class($this);
  44. $template = ($this->template) ? $this->template : substr($class, 0, -6 /*strlen('Action')*/);
  45. $dir = array_slice(explode('/', Load::getFilePath($class)), -2, 1);
  46. return '/actions/' . array_pop($dir) . '/' . $template;
  47. }
  48. public function fetch()
  49. {
  50. $this->view->assignObject($this);
  51. return $this->view->fetch($this->getTemplate());
  52. }
  53. }