0

I've worked on this code base and it responds with html when i access a site www.site.com/version/

However, If i access www.site.com/version?format=xml, it displays output in xml.

How can I change the Zend code to ONLY output in XML irrespective of the format request? Yeah, i'm new to Zend coding...)

My code is exactly what Chris has ( http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/ ) :

class VersionController extends Zend_Rest_Controller
{  
public function init()
{
    $bootstrap = $this->getInvokeArg('bootstrap');

    $options = $bootstrap->getOption('resources');

    $contextSwitch = $this->_helper->getHelper('contextSwitch');
    $contextSwitch->addActionContext('index', array('xml','json'))->initContext();

    //$this->_helper->viewRenderer->setNeverRender();   
    $this->view->success = "true";
    $this->view->version = "1.0";
}
 ...
 ...

1 Answer 1

1

You can force the context to use XML only by following code:

$this->_helper->contextSwitch()->initContext('xml');

Refer link:

http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch.initcontext

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.