見代碼:1.
class TestController extends Zend_Controller_Action {
/**
* The default action - show the home page
*/
public function indexAction() {
$content = "
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” 博客,請務必保留此出處http://phpbob.blog.51cto.com/636017/631102
沒有留言:
張貼留言