Php codeigniter中restful api的方法名是什么?

Php codeigniter中restful api的方法名是什么?,php,codeigniter,Php,Codeigniter,假设我的控制器名为Api_示例,并且扩展了REST_控制器。 现在我的困惑是 public function user_get(){ //Some code.. } public function user_post(){ //Some code.. } 现在,我无法理解该方法中的“用户”是什么。如果我访问user\u get()方法,比如localhost/api\u example/user/get或localhost/api\u example/user/post只是为了以jso

假设我的控制器名为Api_示例,并且扩展了REST_控制器。 现在我的困惑是

public function user_get(){
//Some code..
}
public function user_post(){
    //Some code..
}
现在,我无法理解该方法中的“用户”是什么。如果我访问
user\u get()
方法,比如
localhost/api\u example/user/get
localhost/api\u example/user/post
只是为了以
json
格式显示一些
array
数据。它不起作用。

请帮助我。

您可以使用以下url[获取请求]:

YOUR_BASE_URL/api/example/users

您只能通过浏览器访问GET方法:

localhost/index.php/api_example/user
若你们想访问POST方法,你们必须发送一个POST请愿书,你们可以在这里阅读更多关于POST、GET、PUT和DELETE的信息

前缀是函数的名称,您可以根据需要命名,重要的是sufix GET、POST、PUT或DELETE。index是默认函数的名称,url是
[server]/index.php/[controller\u name]/[function\u name]

例如:

localhost/index.php/api_example/user
localhost是服务器名

php是用于访问控制器文件夹的codeigniter url段

api_示例是控制器的名称


user是函数的名称(函数user_get(){…})

谢谢您的回答。但我想知道“user_get()”中像“user”这样的前缀词到底是什么。我看过很多例子,但有人用过“index_get()/index_post()”。在你解释之前我都理解了,现在如果我按照这个过程,我会得到一个“unknown method”的user_post()例外。我必须在routes.PHP中更改任何内容吗?现在我已经提到了['api_示例/user/(:any)]=['api_示例/user_post']。但我不确定。您不能从浏览器访问POST方法,只能获取方法,您可以通过ajax或一些chrome扩展访问POST方法。url是相同的,只更改类型,如果类型是POST,则自动访问函数user_POST(){…},如果类型是GET access函数user_GET(){…},非常感谢。你救了我一天。我使用了firefox扩展-。