我有如下所示的 Zend 代码:
$contextSwitch->addActionContext('get', array('xml','json'))->initContext();
如何更改它以使其仅返回 XML 格式的数据?抱歉,我是 Zend 编程的新手!
我有如下所示的 Zend 代码:
$contextSwitch->addActionContext('get', array('xml','json'))->initContext();
如何更改它以使其仅返回 XML 格式的数据?抱歉,我是 Zend 编程的新手!
阅读手册
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
//...
}
如果您只将 xml 用于特定操作,请在要返回 xml 的操作内设置标题:
$this->getResponse()->setHeader('Content-type', 'text/xml');
然后根据需要处理其余的操作。如果不启用上下文切换,则视图将成为操作的默认值(即 actioname.phtml)
您可能还想禁用您的布局:
$this->_helper->layout->disableLayout();