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.

46 lines
1023 B

11 years ago
13 years ago
13 years ago
  1. <?php namespace Majestic\App;
  2. /**
  3. * AjaxAction
  4. *
  5. * @copyright NetMonsters <team@netmonsters.ru>
  6. * @link http://netmonsters.ru
  7. * @package Majestic
  8. * @subpackage app
  9. * @since 2011-04-27
  10. */
  11. /**
  12. * Base class for all ajax Actions
  13. */
  14. abstract class AjaxAction extends Action
  15. {
  16. /**
  17. * Data to output
  18. * @var mixed
  19. */
  20. public $data = false;
  21. /**
  22. * Use json_encode
  23. * @var bool
  24. */
  25. protected $json_encode = true;
  26. function __construct()
  27. {
  28. parent::__construct();
  29. $this->template = 'ajax';
  30. }
  31. function fetch()
  32. {
  33. if ($this->json_encode === true) {
  34. header("Content-type: application/json; charset=utf-8");
  35. } else {
  36. header("Content-type: text/html; charset=utf-8");
  37. }
  38. header("Cache-Control: no-store, no-cache, must-revalidate");
  39. $this->view->assign('data', $this->json_encode ? json_encode($this->data) : $this->data);
  40. return $this->view->fetch($this->getTemplate());
  41. }
  42. }