phpzend-frameworkzend-rest

Change addActionContext() to be XML only


I've got Zend code which looks like this:

$contextSwitch->addActionContext('get', array('xml','json'))->initContext();

How can I change this so that it ONLY returns XML formatted data? SOrry, I'm new to Zend programming.!


Solution

  • Read the manual

    public function init()
    {
        $this->_helper->contextSwitch()
            ->addActionContext('get', array('xml','json'))
            ->initContext();
    }
    
    public function getAction()
    {
        this->_helper->contextSwitch()->initContext('xml'); //will always use xml if action has xml context
        //...
    }