gpt4 book ai didi

codeigniter - Backbone JS 和 CodeIgniter REST 服务器

转载 作者:行者123 更新时间:2023-12-01 11:51:15 24 4
gpt4 key购买 nike

我有一个标准的 CI 网络应用程序,但我决定使用 Backbone 按顺序获取困惑的 javascript。我对各种 Controller 方法有一大堆序列化表单/jQuery AJAX 请求:authenticate、change_password、register_member、request_new_password 等,但不太了解 REST 是如何工作的。我正在为 CI 使用 Phil Sturgeon 的 REST 库 https://github.com/philsturgeon/codeigniter-restserver

每个主干模型都应该有不同的 api url 吗?我实际上应该如何调用 Controller 方法?

<?php  
require(APPPATH.'/libraries/REST_Controller.php');
class RestApi extends REST_Controller
{
function get()
{

但它只是 404。

我只是不明白如何根据少数 HTTP 方法替换到我的 50 个旧方法的路由。 Backbone 模型的名称是否需要与服务器端的名称匹配?

最佳答案

您必须将函数命名为 index_HTTPMETHOD。在您的示例中,它将是:

class RestApi extends REST_Controller {
// this will handle GET http://.../RestApi
function index_get() {
}

// additionally this will handle POST http://.../RestApi
function index_post() {
}
// and so forth

// if you want to POST to http://.../RestApi/somefunc
function somefunc_post() {
}

}

关于codeigniter - Backbone JS 和 CodeIgniter REST 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11292968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com