承接 phpactiveresource/phpactiveresource 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phpactiveresource/phpactiveresource

最新稳定版本:1.0.0-stable

Composer 安装命令:

composer require phpactiveresource/phpactiveresource

包简介

A PHP client library for easily accessing Ruby on Rails-based REST services.

README 文档

README

Click here to lend your support to: phpactiveresource and make a donation at www.pledgie.com !

This is a PHP class for accessing Ruby on Rails REST APIs in an ActiveResource style of coding. The benefit is easier use of RoR-based REST services without having to roll your own CURL-based client each time. Hopefully this class saves a few people some time coding in PHP against RoR-based REST services. It’s by no means an exhaustive port, and some methods are missing, but it does try to cover all the basics.

Note: You will need the php curl extension installed on your system. On Ubuntu, you can install it via:

sudo apt-get install php5-curl

Usage

With Composer

Create a composer.json file with the following:

{
	"require": {
		"phpactiveresource/phpactiveresource": "dev-master"
	}
}

Now load the script via Composer’s autoloader:

<?php

require_once 'vendor/autoload.php';

use ActiveResource\ActiveResource;

class Song extends ActiveResource {
	public $site = 'http://localhost:3000/';
	public $element_name = 'songs';
}

// etc.

?>

Without Composer

<?php

require_once ('lib/ActiveResource.php');

class Song extends ActiveResource {
    var $site = 'http://localhost:3000/';
    var $element_name = 'songs';
}

// create a new item
$song = new Song (array ('artist' => 'Joe Cocker', 'title' => 'A Little Help From My Friends'));
$song->save ();

// fetch and update an item, chaining statements
$song->find (44)->set ('title', 'The River')->save ();

// fetch and update, line by line
$song->find (44);
$song->title = 'The River';
$song->save ();

// get all songs
$songs = $song->find ('all');

// delete a song
$song->find (44);
$song->destroy ();

// custom method
$songs = $song->get ('by_year', array ('year' => 1999));

?>

Extra URL params

If you want to add extra params to the end of the url eg: an API key, you can set $extra_params

<?php

require_once ('lib/ActiveResource.php');

class Song extends ActiveResource {
    var $site = 'http://localhost:3000/';
    var $element_name = 'songs';
    var $extra_params = '?key=123456789';
}

Extra Http Headers

If you need to add extra http request headers you can set $request_headers

<?php

require_once ('lib/ActiveResource.php');

class Song extends ActiveResource {
    var $site = 'http://localhost:3000/';
    var $element_name = 'songs';
    var $request_headers = array("x-api-key: some-api-key-here");
}

See the Github Wiki pages for more examples and documentation.

统计信息

  • 总下载量: 8.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 116
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 115
  • Watchers: 5
  • Forks: 26
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-01-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固