2015-12-21 37 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']。但我不確定。 –

相關問題