1

このRestserverをCodeIgniterと組み合わせて使用​​しています。

このようなURLを使用する場合を除いて、かなりうまく機能しているようです。mydomain.com/api/example/1234/

ここで、1234は私が要求しているIDです。

このようなコードは機能しないようです:

class Example extends REST_Controller {
    public function index_get() {
        print($this->get("example"));
    }
}

GETリクエストかPOSTリクエストかは問題ではないようです。URLからIDを取得する方法が必要です。

4

2 に答える 2

0

URL のセグメントは次のようになります。

api = Controller
example = Resource

パラメータはキーと値のペアにする必要があります。

id = Key
1234 = Value

あなたの 1234 はキーとして扱われているようですが、その価値はありません。URL を次のように変更してみてください:mydomain.com/api/example/id/1234/に変換すると、次のようになります。mydomain.com/controller/resource/key/value/

ここにも非常に詳細なチュートリアルがあります: http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/

編集: コントローラーはサブフォルダーにあるため、URL のセグメントは次のように構成する必要があります。

api/example = Controller
user = Resource // basically the method name + the http method e.g. user_get(), or user_post(). I just made 'user' up, for your app can be whatever it is that people will access via your api

パラメータはキーと値のペアとして指定する必要があります。

id = Key
1234 = Value

したがって、URL は次のようになります。mydomain.com/api/example/user/id/1234/

于 2013-01-30T17:46:11.167 に答える