We will
use the RAW document type.
The RAW format is used when a format value is provided in the
request, and is not equal to Feed, HTML, PDF, or Error.
Before we start, we need to consider the data we are going to retrieve. We'll work
with a basic table, #__items, with three fields, id, name, and text. When a request is
made we return a single record from the table.
The first thing we need to do is create the RAW view. To do this we create a new
PHP file called view.raw.php in the items view (the view in which we create this file
is based on the entity).
Once we have created this, we need to add a view class to the file; this is the same
as it would be for any other view in a component. Our next job is to build the
display() method.
This method is essentially very similar to the display() method that would be
located in the item's view.html.php file. The first thing we need to do in this method
is retrieve the data:
// get the data
$data =& $this->get('Data');
No surprises here. This retrieves the data from the item model using the
getData() method.
Pages:
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391