3

私は codeigniter の Phil rest ライブラリを使用しています。彼のドキュメントによると、残りの API は必要な数のパラメーターを持つことができるため、URL は次のように構成されています。

/method/{resource/value}

これはこれに変換されます

/users/id/1

/users/id/1/order/desc のように、さらに属性を追加できます。

ただし、デフォルトでは、バックボーンは次のようにリクエストを送信します。

 /users/1 

THE HTTP VERB USED は、実行するアクションを定義します

したがって、この質問は 2 in 1 です。 質問 1 クライアント側のバックボーン モデルの観点から、phil の Codeigniter インターフェイスに一致する新しい URL 構造を定義するにはどうすればよいですか? 質問 2 次に、ID を隠して値を渡すだけのバックボーンの URL のように、Phil の Codeigniter ライブラリをより単純な URL に応答させることが可能かどうかを知りたいです。

 instead of this -> /users/id/1  use this -> /users/1

編集

質問 2 については、Codeigniter のURI セグメントを使用できることがわかりました。しかし、これを行うためのより良い方法はありますか?

<?php defined('BASEPATH') OR exit('No direct script access allowed');

    /**
     * Example
     *
     * This is an example of a few basic user interaction methods you could use
     * all done with a hardcoded array.
     *
     * @package CodeIgniter
     * @subpackage  Rest Server
     * @category    Controller
     * @author      Phil Sturgeon
     * @link    http://philsturgeon.co.uk/code/
    */

    // This can be removed if you use __autoload() in config.php OR use Modular Extensions
    require APPPATH.'/libraries/REST_Controller.php';

    class Resource extends REST_Controller
    {
        function action_get(){
               $data = array('method'=>'PUT','id'=>$this->uri->segment(3));
               $this->response($data, 200); // 200 being the HTTP response code          
        } 
        function action_post(){
               $data = array('method'=>'POST','id'=>$this->uri->segment(3));
               $this->response($data, 200); // 200 being the HTTP response code          
        }     
        function action_delete(){
               $data = array('method'=>'DELETE','id'=>$this->uri->segment(3));
               $this->response($data, 200); // 200 being the HTTP response code          
        }    
        function action_put(){
           $data = array('method'=>'DELETE','id'=>$this->uri->segment(3));
           $this->response($data, 200); // 200 being the HTTP response code          
        }
}

情報を要求するには、 /Resource/method/{id}を実行する必要があり ます。id は、コントローラーに渡したい値です。あとは HTTP Verb が行います。

どうもありがとうございました。

4

0 に答える 0