Tôi gặp sự cố khi trả về XML trong ứng dụng ZF của mình. Mã của tôi:Cách trả về XML trong ứng dụng Zend Framework
class ProjectsController extends Gid_Controller_Action
{
public function xmlAction()
{
$content = "<?xml version='1.0'><foo>bar</foo>";
header('Content-Type: text/xml');
echo $content;
}
}
Tôi cũng đã thử như sau:
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();
}
}
Có thể ai đó chỉ cho tôi đi đúng hướng như thế nào để đạt được điều này?
làm thế nào để làm điều tương tự trong Zend Framework 3? –