从这段代码中我得到了我想要的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>...
由于空行,我收到错误:
“此页面包含以下错误:
第6行第2行的错误:仅在开始时允许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>