siliconpi
siliconpi

Reputation: 8287

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.!

Upvotes: 3

Views: 1135

Answers (2)

Xerkus
Xerkus

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

Ashley
Ashley

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

Related Questions