2011-04-27 18:33:57 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AjaxAction
|
|
|
|
*
|
|
|
|
* @copyright NetMonsters <team@netmonsters.ru>
|
2012-11-10 16:06:19 +04:00
|
|
|
* @link http://netmonsters.ru
|
2012-03-19 18:18:25 +04:00
|
|
|
* @package Majestic
|
2012-11-10 16:06:19 +04:00
|
|
|
* @subpackage app
|
|
|
|
* @since 2011-04-27
|
2011-04-27 18:33:57 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-11-10 16:06:19 +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
|
|
|
|
{
|
2012-11-10 16:06:19 +04:00
|
|
|
/**
|
|
|
|
* Data to output
|
|
|
|
* @var mixed
|
|
|
|
*/
|
2012-11-11 13:51:38 +04:00
|
|
|
public $data = false;
|
2011-10-13 14:55:06 +04:00
|
|
|
|
2012-11-10 16:06:19 +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
|
|
|
{
|
2012-11-10 16:06:19 +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");
|
2012-11-10 16:06:19 +04:00
|
|
|
$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
|
|
|
}
|
|
|
|
}
|