Codeigniter:使用RESTful服务

3
有没有一个易于设置的Codeigniter REST库,可以用来消费RESTful服务?我尝试设置了this库。但是无法设置Spark。尝试了以下步骤:
  1. 在您的Codeigniter目录根目录下添加名为sparks的目录
  2. 在application/core/MY_Loader.php中添加自定义Loader类。
它给了我另一个错误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']);
        }

我收到了一个错误:调用未定义的方法CI_Loader::spark()


你是正确的,我编辑了我的评论。这些库的作者试图让人们使用Sparks,因此他改变了其中一些库,因此有了他的“顽固”的评论等。你不需要使用Sparks。任何被称为“Spark”的东西都可以像库一样下载和使用。 - cartalot
请访问以下链接:http://getsparks.org/packages/curl/versions/HEAD/show,找到“download manually”并下载所需内容。 - cartalot
2个回答

2
“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

教程结束时,有许多评论和问题,作者已回答了其中的许多问题。
编辑 - 糟糕,我忘记你必须更改一行。并且您需要下载CI curl库。好的,在REST客户端中,在文件Rest.php中从第53行开始。
/* 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');

如果您能够在没有Spark的情况下安装“rest client”,请告诉我窍门。因为我从“Rest.php”收到了有关Spark的错误信息。 - Himanshu Yadav

0

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

php tools/spark install -v1.2.1 curl

源代码


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接