Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php BackboneJS+;Codeigniter RESTful API-如何传递$startdate和$enddate_Php_Codeigniter_Rest_Backbone.js - Fatal编程技术网

Php BackboneJS+;Codeigniter RESTful API-如何传递$startdate和$enddate

Php BackboneJS+;Codeigniter RESTful API-如何传递$startdate和$enddate,php,codeigniter,rest,backbone.js,Php,Codeigniter,Rest,Backbone.js,我有一个以Codeingiter为后端的主干应用程序。我使用RESTfulAPI设置在这些框架之间来回传递数据 现在我想有一个视图显示“最新追随者”,为此我创建了一个API,如下所示: public function new_artist_followers_get($start_date, $end_date) { $this->load->database(); $sql = "SELECT users.img_name FROM artist_follow

我有一个以Codeingiter为后端的主干应用程序。我使用RESTfulAPI设置在这些框架之间来回传递数据

现在我想有一个视图显示“最新追随者”,为此我创建了一个API,如下所示:

public function new_artist_followers_get($start_date, $end_date)  
{ 
    $this->load->database();
    $sql = "SELECT users.img_name FROM artist_followers INNER JOIN artists ON artists.artist_id = artist_followers.artist_id INNER JOIN users ON users.user_id = artist_followers.user_id
                WHERE artist_followers.artist_id = artists.artist_id AND date_time BETWEEN '$start_date' AND '$end_date' LIMIT 20";
    $query = $this->db->query($sql);
    $data = $query->result();

    if($data) {
        $this->response($data, 200); 
    } else {
        $this->response(array('error' => 'Couldn\'t find any artist followers!'), 404);
    }
}
artistbioCollection.fetch({
  data: {
    start_date: this.startdate,
    end_date: this.enddate
  }
});
我的问题是,我真的不知道如何将日期传递到我的主干前端?我必须这样做吗

NewFollowers.NewFollowersCollection = Backbone.Collection.extend({
    url: function() {
        return '/projects/testproject/index.php/api/testfile/new_artist_followers/'+ this.artist_id + this.startdate + this.enddate;
        }
});
通常,我获取的API与上面的示例完全相同,只是没有
this.startdate
this.enddate
,然后在我的主视图中收集所有内容,在这里,我为每个API/集合执行以下操作(在本例中为艺术家传记):

}


有人能帮我吗?

Backbone.Collection
fetch
方法接受额外的参数,它们应该这样传递:

public function new_artist_followers_get($start_date, $end_date)  
{ 
    $this->load->database();
    $sql = "SELECT users.img_name FROM artist_followers INNER JOIN artists ON artists.artist_id = artist_followers.artist_id INNER JOIN users ON users.user_id = artist_followers.user_id
                WHERE artist_followers.artist_id = artists.artist_id AND date_time BETWEEN '$start_date' AND '$end_date' LIMIT 20";
    $query = $this->db->query($sql);
    $data = $query->result();

    if($data) {
        $this->response($data, 200); 
    } else {
        $this->response(array('error' => 'Couldn\'t find any artist followers!'), 404);
    }
}
artistbioCollection.fetch({
  data: {
    start_date: this.startdate,
    end_date: this.enddate
  }
});
它在

因此这里,
data
与jQuery.ajax
data
属性是相同的属性,然后您可以像往常一样在服务器端获取这些值


当fetch执行
GET
请求时,传递给
数据的所有参数都将附加到查询字符串中,您应该使用URI模板在服务器端定义URI,如下所示:

http://example.com/api{/artist,id}/followers{?stardate,enddate}
之后,您可以在客户端使用params填充此模板。您可以为这些参数添加自定义设置程序,例如(未测试):

请注意,这不是一个完整的REST解决方案。通过REST,您可以获得超媒体响应,其中包含链接。其中一个链接可以包含实际的URI模板和参数描述。因此,您的客户机与URI结构完全解耦,它不知道如何构建URI,但知道如何评估URI模板,这是一个标准解决方案。使用标准解决方案将客户机与服务的实现分离,这称为REST的统一接口约束