Reputation: 8287
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.!
Upvotes: 3
Views: 1135
Reputation: 2705
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
//...
}
Upvotes: 2
Reputation: 5947
If you only ever use xml for a particular action, set the headers inside the action you want to return xml:
$this->getResponse()->setHeader('Content-type', 'text/xml');
And then process the rest of the action as you need it to. Without context switching enabled the view will be the default for the action (ie. actioname.phtml)
You will probably also want to disable your layout:
$this->_helper->layout->disableLayout();
Upvotes: 0