3

RESTful サービスを利用するために使用できる、セットアップが簡単な Codeigniter REST ライブラリはありますか? このライブラリをセットアップしてみました。しかし、セットアップできませんでしたSpark。次の手順を試しました:

  1. codeigniter ディレクトリのルートに sparks という名前のディレクトリを追加する
  2. カスタム ローダー クラスを application/core/MY_Loader.php に追加します。

それは私に別のエラーを与えましたCannot find spark path at sparks/curl/1.2.1/。今、私は立ち往生しています。codeigniter で RESTful API をセットアップするのがなぜそんなに難しいのか疑問に思っています。

更新:実行しようとすると

$this->load->spark('restclient/2.1.0');
        // Load the library
        $this->load->library('rest');
        // Run some setup
        $this->rest->initialize(array('server' => 'http://api.twitter.com/'));
        // Pull in an array of tweets
        $tweets = $this->rest->get('1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=jenksuy&count=2');
        $tweetobjects = json_decode($tweets);
        foreach ($tweetobjects['results'] as $tweet) {
            log_message('info', $tweet['text']);
        }

私は得ていますError: Call to undefined method CI_Loader::spark()

4

2 に答える 2

2

sparks は必要ありません。編集を参照してください。このチュートリアルを使用して開始します。著者はライブラリも作成しました

http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/

チュートリアルを使用するには、次の 2 つをダウンロードしてください。

https://github.com/philsturgeon/codeigniter-restserver

https://github.com/philsturgeon/codeigniter-restclient

チュートリアルの最後にも - 多くのコメントや質問があり、チュートリアルの作成者はそれらの多くに回答しています

編集 - おっと、1行変更する必要があるのを忘れていました。CI curl ライブラリを DL する必要があります。残りのクライアントで、53行目から始まるファイルRest.phpでOK

/* Not using Sparks? You bloody well should be.
    | If you are going to be a stick in the mud then do it the old fashioned way

    $this->_ci->load->library('curl');
    */

    // Load the cURL spark which this is dependant on
    $this->_ci->load->spark('curl/1.2.1');

そのため、従来の方法でcurlライブラリをロードするように変更し、spark参照をコメントアウトします

        $this->_ci->load->library('curl');


    // Load the cURL spark which this is dependant on
    // $this->_ci->load->spark('curl/1.2.1');
于 2013-08-08T00:57:14.233 に答える
0

アプリケーション ルート (アプリケーション フォルダーではない) で次のコマンドを実行して、curl 1.2.1 をインストールできます。

php tools/spark install -v1.2.1 curl

ソース

于 2015-08-14T08:19:43.363 に答える