PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Returning Custom XML Responses

If you wish to return custom XML, simply return a DOMDocument, DOMElement or SimpleXMLElement object.

Example 703. Return Custom XML

<?php
/**
 * Say Hello
 *
 * @param string $who
 * @param string $when
 * @return SimpleXMLElement
 */
function sayHello($who$when)
{
    
$xml ='<?xml version="1.0" encoding="ISO-8859-1"?>
<mysite>
    <value>Hey $who! Hope you\'re having a good $when</value>
    <code>200</code>
</mysite>'
;

    
$xml simplexml_load_string($xml);
    return 
$xml;
}

$server = new Zend_Rest_Server();
$server->addFunction('sayHello');

$server->handle();

The response from the service will be returned without modification to the client.

Zend Framework