是否有一个易于设置的Codeigniter REST库,我可以使用它来使用RESTful服务?我尝试设置this库。但无法设置Spark
。尝试以下步骤:
它给了我另一个错误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()
答案 0 :(得分:2)
不需要火花查看编辑。使用本教程开始,作者还编写了库
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
也在本教程的最后 - 有很多评论和问题,而且教程作者已经回答了很多这些问题
编辑 - 哎呀忘了你必须换一行。你将需要DL CI卷曲库。好吧,在休息客户端,从第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');
答案 1 :(得分:0)