0

I'm writing a Joomla 2.5 or 3.x component which make data elaboration and returns some data.

I want that work as a service that is invoked and returns data (eg I call www.mysite.com?option=com_mycomponent&view=myview

and result for example my json data ..or xml or what i need after my elaboration )

so i need that my output view is raw. i need no template and no css or js.. only my result..

but now the results are inserted into the template

Is it possible?...

I tried to create a RAW mode in my template like Here .

this works but is not what I want but it is a dirty solution because it work if the url i have to call is like ... www.mysite.com~....~&tmpl=raw

I'd like my component can output as raw.

Thanks

Community
  • 1
  • 1
  • You will find these useful: [raw format view](http://stackoverflow.com/questions/20905567/joomla-3-how-do-i-use-the-raw-format-without-adding-format-raw-to-the-url/20914010#20914010) ,and, [json output](http://stackoverflow.com/questions/16715801/joomla-component-controller-not-returning-json). – ilias Jan 09 '14 at 17:24
  • Or you can just output data and die in view.raw.php – di3sel Jan 09 '14 at 23:03

1 Answers1

1
  1. Create RAW view views/[myview]/view.raw.php inside your component
  2. In requests require RAW format index.php?option=com_mycomponent&view=myview&format=raw.

Like in com_banners/views/tracks/view.raw.php.

Sames goes for JSON and XML.

Here's a list of generic document formats: libraries/joomla/document

  • feed
  • html
  • image
  • json
  • opensearch
  • raw
  • xml

To use JSON format in response, I recommend new JResponseJson class:

// Anything that may be serialized with json_encode or an Exception
$data = array('some' => 'data');

echo new JResponseJson($data);
piotr_cz
  • 8,755
  • 2
  • 30
  • 25