Merge pull request #2985 from Mikesch-mp/json-export
Export JSON with .json extension
This commit is contained in:
commit
b0f0464ec4
|
@ -8,6 +8,7 @@ use Icinga\Exception\QueryException;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Data\Filterable;
|
use Icinga\Data\Filterable;
|
||||||
use Icinga\File\Csv;
|
use Icinga\File\Csv;
|
||||||
|
use Icinga\Util\Json;
|
||||||
use Icinga\Web\Controller as IcingaWebController;
|
use Icinga\Web\Controller as IcingaWebController;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
|
|
||||||
|
@ -39,8 +40,13 @@ class Controller extends IcingaWebController
|
||||||
}
|
}
|
||||||
if ($this->_getParam('format') === 'json'
|
if ($this->_getParam('format') === 'json'
|
||||||
|| $this->_request->getHeader('Accept') === 'application/json') {
|
|| $this->_request->getHeader('Accept') === 'application/json') {
|
||||||
header('Content-type: application/json');
|
$response = $this->getResponse();
|
||||||
echo json_encode($query->getQuery()->fetchAll());
|
$response
|
||||||
|
->setHeader('Content-Type', 'application/json')
|
||||||
|
->setHeader('Cache-Control', 'no-store')
|
||||||
|
->setHeader('Content-Disposition', 'inline; filename=' . $this->getRequest()->getActionName() . '.json')
|
||||||
|
->appendBody(Json::encode($query->getQuery()->fetchAll()))
|
||||||
|
->sendResponse();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
if ($this->_getParam('format') === 'csv'
|
if ($this->_getParam('format') === 'csv'
|
||||||
|
|
Loading…
Reference in New Issue