开发者

URL of a collection in Backbone for RESTful interaction

Here is a collection I define in backbone.js

    var List=Backbone.Collection.extend({
        model: Item,
        url: "TodoApp/index.php/todo"
    });
    var list=new List

Then I created a Model in the collection with an ID=80 Now, when I do list.fetch(); It will make a call to 开发者_如何学运维 "TodoApp/index.php/todo/80"

However, at the backend, using Codeigniter, I really need to have

    TodoApp/index.php/todo/get/82.........where get is a function I defined to access DB

So, should I change the Collection url to "TodoApp/index.php/todo/get"

But again, that's not really where the resource is located?


In route.php try:

$route['todo/(:num)'] = "todo/get/$1";


HERE is what I ended up doing.

I renamed the index of the controller to resource therefore using a URL of: TodoApp/index.php/todo/resource

When getting a GET request at TodoApp/index.php/todo/resource/80

extract the second segment of the URI and read from DB with that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜