2015-12-21 99 views
1

考虑我的控制器名称是Api_example,并且我扩展了REST_Controller。 现在我的困惑是codeigniter中restful api的方法名称是什么?

public function user_get(){ 
//Some code.. 
} 
public function user_post(){ 
    //Some code.. 
} 

现在,我无法理解什么是“用户”在那种方法。如果我访问user_get()方法,如localhost/api_example/user/getlocalhost/api_example/user/post只是显示一些arraydatajson格式。它不工作。 请帮帮我。

回答

0

您可以使用下面的网址[为GET请求]:

YOUR_BASE_URL/api/example/users 
1

你只可以访问通过浏览器获取方法:

localhost/index.php/api_example/user 

如果你想获得POST方法,你必须发送一个帖子请愿书,你可以阅读更多关于POST,GET,PUT和DELETE,这里What is difference between HTTP methods GET, POST, PUT and DELETE

前缀是函数的名字,你可以按你的意思命名,重要的是t他修改GET,POST,PUT或DELETE。指数名称为默认功能,网址是[server]/index.php/[controller_name]/[function_name]

例如:

localhost/index.php/api_example/user 

本地主机是服务器名。

index.php是访问控制器文件夹的codeigniter url段。

api_example是控制器的名称。

用户是函数的名称(函数user_get(){...})

+0

感谢您的回答。但我想知道'user_get()'中的'user'这个前缀词是什么。我看过很多例子,但有人使用'index_get()/ index_post()'。 –

+0

我编辑我的答案,我希望我帮你 –

+0

我明白,直到你expalined,现在,如果我遵循该过程,我得到一个'未知方法'exceptionfor user_post()。我需要改变route.PHP中的任何内容吗?现在我已经提到['api_example/user /(:any)'] = ['api_example/user_post']。但我不确定。 –

相关问题