apexwire/yii2-restclient

用于将API作为ActiveRecord用于Yii2的工具

安装数: 3,534

依赖项: 0

建议者: 0

安全: 0

星标: 13

关注者: 4

分支: 4

类型:yii2-extension

0.4.3 2017-04-21 14:39 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:31:03 UTC


README

将API作为ActiveRecord用于Yii2的工具

使用您的API作为ActiveRecord

安装

首选通过 composer 安装扩展。

运行

php composer.phar require "apexwire/yii2-restclient"

或在您的 composer.json 文件的 "require" 部分

"apexwire/yii2-restclient": "*"

中添加

配置

将此代码添加到您的配置文件中

    'components' => [
        'restclient' => [
            'class' => 'apexwire\restclient\Connection',
            'config' => [
                'base_uri' => 'https://api.site.com/',
            ],
        ],
    ],

应用

定义您的模型

class MyModel extends \apexwire\restclient\ActiveRecord
{
    public function attributes()
    {
        return ['id', 'name', 'status'];
    }
}

调试

调试面板连接示例

$config['modules']['debug'] = [
    'class' => 'yii\debug\Module',
    'panels' => [
        'rest' => ['class' => 'apexwire\restclient\DebugPanel'],
    ],
];

功能

  • 可以指定返回的字段列表: MyModel::find()->select(['id','name'])
  • 可以指定限制: MyModel::find()->limit(2)
  • 支持分页
  • 支持排序
  • 支持搜索。示例 在此

许可证

本项目以 BSD-3-Clause 许可证发布。更多信息 在此

版权 © 2016, ApexWire

感谢