开发者

Change addActionContext() to be XML only

I've got Zend code which looks like this:

$contextSwitch->addActio开发者_开发百科nContext('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.!


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
    //...
}


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜