Source for file json.php
Documentation is available at json.php
* @package FrameworkOnFramework
* @copyright Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
// Protect from unauthorized access
* FrameworkOnFramework JSON View class. Renders the data as a JSON object or
* array. It can optionally output HAL links as well.
* @package FrameworkOnFramework
* When set to true we'll add hypermedia to the output, implementing the
* HAL specification (http://stateless.co/hal_specification.html)
* @param array $config The component's configuration array
if (isset
($config['use_hypermedia']))
* The event which runs when we are displaying the record list JSON view
* @param string $tpl The view sub-template to use
* @return boolean True to allow display of the view
$items =
$model->getItemList();
$document->setMimeEncoding('application/hal+json');
$document->setMimeEncoding('application/json');
if ($result instanceof
Exception)
if ($result instanceof
Exception)
// Default JSON behaviour in case the template isn't there!
$json =
$haldocument->render('json');
$callback =
$this->input->getVar('callback', null);
echo
$callback .
'(' .
$json .
')';
$defaultName =
$this->input->getCmd('view', 'joomla');
$filename =
$this->input->getCmd('basename', $defaultName);
$document->setName($filename);
* The event which runs when we are displaying a single item JSON view
* @param string $tpl The view sub-template to use
* @return boolean True to allow display of the view
protected function onRead($tpl =
null)
$item =
$model->getItem();
$document->setMimeEncoding('application/hal+json');
$document->setMimeEncoding('application/json');
if ($result instanceof
Exception)
if ($result instanceof
Exception)
// Default JSON behaviour in case the template isn't there!
$json =
$haldocument->render('json');
$callback =
$this->input->get('callback', null);
echo
$callback .
'(' .
$json .
')';
$defaultName =
$this->input->getCmd('view', 'joomla');
$filename =
$this->input->getCmd('basename', $defaultName);
$document->setName($filename);
* Creates a FOFHalDocument using the provided data
* @param array $data The data to put in the document
* @param FOFModel $model The model of this view
* @return FOFHalDocument A HAL-enabled document
// Create a new HAL document
// Create relative links in a record list context
$pagination =
$model->getPagination();
if ($pagination->get('pages.total') >
1)
// Try to guess URL parameters and create a prototype URL
// NOTE: You are better off specialising this method
$uri->setVar('limitstart', 0);
$document->addLink('first', new FOFHalLink($uri));
// Do we need a "prev" link?
if ($pagination->get('pages.current') >
1)
$prevPage =
$pagination->get('pages.current') -
1;
$limitstart =
($prevPage -
1) *
$pagination->limit;
$uri->setVar('limitstart', $limitstart);
// Do we need a "next" link?
if ($pagination->get('pages.current') <
$pagination->get('pages.total'))
$nextPage =
$pagination->get('pages.current') +
1;
$limitstart =
($nextPage -
1) *
$pagination->limit;
$uri->setVar('limitstart', $limitstart);
$lastPage =
$pagination->get('pages.total');
$limitstart =
($lastPage -
1) *
$pagination->limit;
$uri->setVar('limitstart', $limitstart);
* Convert an absolute URI to a relative one
* @param string $uri The URI to convert
* @return string The relative URL
static $root =
null, $rootlen =
0;
$root =
rtrim(JURI::base(), '/');
if (substr($uri, 0, $rootlen) ==
$root)
$uri =
substr($uri, $rootlen);
* Returns a JUri instance with a prototype URI used as the base for the
* other URIs created by the JSON renderer
* @return JUri The prototype JUri instance
$protoUri =
new JUri('index.php');
$protoUri->setQuery($this->input->getData());
$protoUri->delVar('savestate');
$protoUri->delVar('base_path');
Documentation generated on Tue, 19 Nov 2013 15:06:16 +0100 by phpDocumentor 1.4.3