使用Zend Framework输出xml方法
Zend Framework 输出xml的几种方法。见代码:
1.
class TestController extends Zend_Controller_Action { /** * The default action - show the home page */ public function indexAction() { $content = "<?xml version='1.0'?><foo>bar</foo>"; header('Content-Type: text/xml'); echo $content; exit; } } 加一句exit;这样可以不用关闭view.
2.
class TestController extends Zend_Controller_Action { /** * The default action - show the home page */ public function indexAction() { // XML-related routine $xml = new DOMDocument('1.0', 'utf-8'); $xml->appendChild($xml->createElement('foo', 'bar')); $output = $xml->saveXML(); // Both layout and view renderer should be disabled Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); Zend_Layout::getMvcInstance()->disableLayout(); // Setting up headers and body $this->_response->setHeader('Content-Type', 'text/xml; charset=utf-8') ->setBody($output); } } 第二种方法可以调用DOMDocument对象来创建更丰富的xml.
本文出自 “Bob” 博客
相关新闻>>
- 发表评论
-
- 最新评论 更多>>