是否有一个易于设置的 Codeigniter REST 库,我可以用它来使用 RESTful 服务?我尝试设置this https://github.com/philsturgeon/codeigniter-restclient图书馆。但无法设置Spark
。尝试了以下步骤:
- 在 codeigniter 目录的根目录中添加名为 Sparks 的目录
- 将自定义加载器类添加到 application/core/MY_Loader.php。
它给了我另一个错误Cannot find spark path at sparks/curl/1.2.1/
。现在我被困住了。想知道为什么在 codeigniter 中设置 RESTful API 如此困难。
Update:当我尝试跑步时
$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()
火花是不必要的请参阅编辑。使用本教程开始,作者还编写了库
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-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-restserver
https://github.com/philsturgeon/codeigniter-restclient https://github.com/philsturgeon/codeigniter-restclient
同样在教程的最后 - 有很多评论和问题,教程作者已经回答了其中的许多问题
编辑 - 哎呀忘了你必须改变一行。并且您将需要 DL CI curl 库。好的,在其余客户端中,在文件 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');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)