I have a custom Joomla 3.4.1 component which has a view that displays data either in JSON format (from views/myview/view.json.php file) or HTML (from views/myview/view.html.php file) format. Is there a way how to change the default view's format from HTML to JSON so that
http://example.com/component/mycomponent/myview
returns JSON data instead of HTML while:
http://example.com/component/mycomponent/myview?format=html
still returns the HTML template of the view?
EDIT:
As far as I get is this router:
function TouristGuideParseRoute($segments) {
$count = count($segments);
$parameters = array();
if ($count > 0) {
$parameters['view'] = $segments[0];
}
if ($count > 1) {
$parameters['task'] = $segments[1];
}
if ($count > 2) {
$parameters['id'] = $segments[2];
}
if ($count > 3) {
$parameters['format'] = $segments[3];
}
if (($parameters['view'] == 'api') && empty($parameters['format'])) {
$application = JFactory::getApplication();
$input = $application->input;
$parameters['format'] = $input->getString('format', 'json');
}
return $parameters;
}
which displays JSON format even if URL contains ?format=html because in this router the $application->input is empty (probably populated later on in Joomla request processing chain) and thus $input->getString('format','json') returns json all the time.
In your controller, set your default format manually like this (Joomla 3)
Hope this can help.