Files
majestic/app/AjaxAction.php

47 lines
999 B
PHP
Raw Normal View History

2011-04-27 18:33:57 +04:00
<?php
/**
* AjaxAction
*
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
2012-03-19 18:18:25 +04:00
* @package Majestic
* @subpackage app
* @since 2011-04-27
2011-04-27 18:33:57 +04:00
*/
/**
* Base class for all ajax Actions
2011-10-13 14:55:06 +04:00
*/
2011-04-27 18:33:57 +04:00
abstract class AjaxAction extends Action
{
/**
* Data to output
* @var mixed
*/
public $data = false;
2011-10-13 14:55:06 +04:00
/**
* Use json_encode
* @var bool
*/
protected $json_encode = true;
2011-04-27 18:33:57 +04:00
function __construct()
{
parent::__construct();
$this->template = 'ajax';
}
2011-04-27 19:16:40 +04:00
function fetch()
2011-04-27 18:33:57 +04:00
{
if ($this->json_encode === true) {
header("Content-type: application/json; charset=utf-8");
} else {
header("Content-type: text/html; charset=utf-8");
}
2011-04-27 18:33:57 +04:00
header("Cache-Control: no-store, no-cache, must-revalidate");
$this->view->assign('data', $this->json_encode ? json_encode($this->data) : $this->data);
2011-04-27 19:16:40 +04:00
return $this->view->fetch($this->getTemplate());
2011-04-27 18:33:57 +04:00
}
}