【问题标题】:Codeigniter: Consume RESTful serviceCodeigniter:使用 RESTful 服务
【发布时间】:2013-08-08 00:06:43
【问题描述】:

是否有一个易于设置的 Codeigniter REST 库,我可以使用它来使用 RESTful 服务?我尝试设置this 库。但无法设置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()

【问题讨论】:

  • 你是对的,我编辑了我的评论。这些图书馆的作者试图让人们使用火花,所以他改变了其中的一些,因此他的“坚持”评论等你不需要使用火花。一点也不。任何“火花”都可以像图书馆一样下载和使用。
  • 像这样 - 我认为你需要 - getsparks.org/packages/curl/versions/HEAD/show 去它说手动下载的地方。

标签: php codeigniter rest


【解决方案1】:

sparks 不是必需的,请参阅编辑。使用本教程开始,作者还编写了库

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

下载这两个以使用教程:

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

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

也在教程的最后——有很多cmets和问题,教程作者已经回答了很多

编辑 - 哎呀忘了你必须改变一行。并且您将需要对 CI curl 库进行 DL。好的,所以在其余客户端中,从第 53 行开始的文件 Rest.php 中

/* 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');

【讨论】:

  • 如果你能在没有火花的情况下安装rest client,请告诉我诀窍。因为我收到来自Rest.php 抱怨 Spark 的错误
【解决方案2】:

您可以通过在应用程序根目录(而不是应用程序文件夹)上运行以下命令来安装 curl 1.2.1:

php tools/spark install -v1.2.1 curl

Source

【讨论】:

    猜你喜欢
    • 2017-12-20
    • 2017-05-14
    • 2015-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-16
    相关资源
    最近更新 更多