LoginSignup
0
1

More than 5 years have passed since last update.

FuelPHPでController_Restを利用したWebAPIでURLエンドポイントにIDを含めたい場合

Posted at

FuelPHPのWebドキュメントを読んでも
https://hogehoge.com/hoge/fuga/[ユーザID] というURLエンドポイントのコントローラのメソッドの作り方が書いていなかったのでメモ。

つぶさにドキュメントみたら書いてあるのかもしれない。

class Controller_Hoge extends Controller_Rest
{
    public function get_fuga($id)    // ★引数に指定する!
    {
        return $this->response(array(
            'foo' => Input::get('foo'),
            'baz' => array(
                1, 50, 219
            ),
            'empty' => null
        ));
    }
}

引数に指定するのがポイント。
https://hogehoge.com/hoge/fuga/[ユーザID] の[ユーザID]に指定した値が
get_fuga メソッド内で$idとして取得できる。

FuelPHPだとAPIのURLが思ったようにするのが難しいのでストレス。
これもドキュメントを隅々まで見れば書いてあるのかもしれないが…

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1