从这段代码中,我得到了我想要的 xml,但它在浏览器中不起作用,因为前面有一个空行
function Users_get(){
$this->load->helper('url');
$this->load->model('User_model');
$data['rows'] = $this->User_model->getUsers();
$f = 1;
foreach ($data['rows'] as $r):
$users[$f] = array(
'user_id' => $r->ID,
'Destination' => $r->Destination);
$f++;
endforeach;
$this->response($users, 200); // 200 being the HTTP response code
}
xml中的结果:
LINE 1 :EMPTY LINE MESSING UP THE ENTIRE OUTPUT
LINE 2 :<?xml version="1.0" encoding="utf-8"?>
LINE 3 :<xml><item><user_id>1</user_id><Destination>Valencia</Destination></item>...
由于空行,我收到错误:
“此页面包含以下错误:
第 2 行第 6 列的错误:仅在文档开头允许 XML 声明 下面是页面的呈现,直到第一个错误。”
JSON 输出正常....
我的观点
<body>
<a href="<?php echo site_url('userAPI/user/user_id/1');?>">Specific user</a>
<br>
<a href="<?php echo site_url('userAPI/alluser');?>">All users</a>
<!-- <p>FlightFrom: <?php //returnJasonName('2');?></p> -->
<br>
<a href="<?php echo site_url('userAPI/Users_get/user_id/1');?>">user from database</a>
<br>
<?php foreach ($rows as $r):?>
<p><?php echo $r->ID;?></p>
<div><?php echo $r->Destination; ?></div>
<?php endforeach; ?>
</body>