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.

65 lines
1.5 KiB

10 years ago
13 years ago
13 years ago
10 years ago
13 years ago
13 years ago
10 years ago
13 years ago
13 years ago
13 years ago
10 years ago
13 years ago
13 years ago
10 years ago
13 years ago
  1. <?php namespace Majestic\App;
  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 \Majestic\View\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 (\Majestic\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. * @param bool $permanently
  36. */
  37. protected function redirect($url = null, $permanently = false)
  38. {
  39. if ($permanently) {
  40. header('HTTP/1.1 301 Moved Permanently');
  41. }
  42. header('Location: ' . (($url) ? $url : \Majestic\Env::getRequestUri()));
  43. exit();
  44. }
  45. protected function getTemplate()
  46. {
  47. $class = get_class($this);
  48. $template = ($this->template) ? $this->template : substr($class, 0, -6 /*strlen('Action')*/);
  49. $dir = array_slice(explode('/', \Majestic\Load::getFilePath($class)), -2, 1);
  50. return '/actions/' . array_pop($dir) . '/' . $template;
  51. }
  52. public function fetch()
  53. {
  54. $this->view->assignObject($this);
  55. return $this->view->fetch($this->getTemplate());
  56. }
  57. }