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.

50 lines
1.1 KiB

  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. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. abstract class Action
  12. {
  13. public function __construct()
  14. {
  15. $this->extractParams();
  16. $this->execute();
  17. }
  18. protected function extractParams()
  19. {
  20. $params = FrontController::getInstance()->getRouter()->getRoute()->getParams();
  21. if ($params) {
  22. foreach ($params as $name => $value) {
  23. if (is_string($name)) {
  24. $this->$name = $value;
  25. }
  26. }
  27. }
  28. }
  29. abstract protected function execute();
  30. /**
  31. * Redirect
  32. *
  33. * @param mixed $url
  34. * @param mixed $relative Default to true
  35. */
  36. protected function redirect($url = null, $relative = true)
  37. {
  38. $url = ($url) ? $url : Env::getRequestUri();
  39. if ($relative) {
  40. $url = FrontController::getInstance()->getBaseUrl() . $url;
  41. }
  42. header('Location: ' . $url);
  43. exit();
  44. }
  45. }