我有一個Codeingiter作爲Backend的骨幹應用程序。我使用RESTful API設置在這些框架之間來回傳遞數據。
現在我想有一個視圖,顯示了我「最新的追隨者」,爲我創造了一個這樣的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);
}
}
我的問題是,我真的不知道如何傳遞約會到我的骨幹前端?我必須以某種方式做這樣的?:
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
,然後在我的MainView我收集的一切,在這裏我對每個API /收藏做到這一點(在這種情況下,藝術家傳記):
beforeRender: function() {
var artistbioCollection = new Artistbio.ArtistbioCollection();
artistbioCollection.artist_id = this.artist_id;
this.insertView('.artistBio', new Artistbio.View({collection: artistbioCollection}));
artistbioCollection.fetch();
....etc. etc. ...
}
因此,誰能幫助我?