我在ZF应用程序中返回XML时遇到问题.我的代码:
class ProjectsController extends Gid_Controller_Action
{
public function xmlAction ()
{
$content = "<?xml version='1.0'><foo>bar</foo>";
header('Content-Type: text/xml');
echo $content;
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过以下方法:
class ProjectsController extends Gid_Controller_Action
{
public function xmlAction ()
{
$content = "<?xml version='1.0'><foo>bar</foo>";
$this->getResponse()->clearHeaders();
$this->getResponse()->setheader('Content-Type', 'text/xml');
$this->getResponse()->setBody($content);
$this->getResponse()->sendResponse();
}
}
Run Code Online (Sandbox Code Playgroud)
有人能指出我正确的方向如何实现这一目标?