0

这个问题与此处找到的 CodeIGniter RESTful API 库有关。我希望这里有人在使用这个库并且可以提供一些帮助:)。

http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/

我已经安装了这个库并用它建立了一个工作环境。我也能够取回数据。为了使用,我创建了一个非常简单的类,我使用以下代码访问它:

<?php

 require APPPATH.'/libraries/REST_Controller.php';

 class Users extends REST_Controller
 {
      public function list_get()
      {
           $this->load->database();

           $data = $this->db->get('users')->result();

           $this->response($data, 200); 
       }

  }

为了访问这个控制器,我调用了以下 URL:

“http://localhost/mgtapp/index.php/api/users/list/format/json”

当我取回数据时,我看到标头内容类型设置为 text/html 而不是 json,并且我还在 php 中收到错误消息,显示“标头已发送”。我试图从 url 的末尾删除格式并通过“接受”发送,但我得到了同样的错误,我看到内容类型被设置为 text/html。当我运行示例时,我看到响应按原样返回(作为内容类型中的 json),所以我不明白我在这里做错了什么,内容类型设置不正确。如果有人能解释一下,那将非常有帮助!

谢谢!

4

1 回答 1

1

所以我回答这个问题是因为我遇到麻烦的原因是愚蠢的。

我的 php 类控制器的“?>”下有几行,显然这把它搞砸了。对不起!

其他有这个问题的人,先检查一下!

于 2012-07-16T07:28:44.563 回答