Download the PHP package devzyj/yii2-rest without Composer
On this page you can find all versions of the php package devzyj/yii2-rest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package yii2-rest
REST Extension for Yii2
增强 yiisoft/yii2-rest 功能,在 Actions 中增加事件。
并且增加了批量操作的 Actions。
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your application's composer.json file.
Usage
调用方法,只列出部分新增的 API:
POST /users/validate: 验证创建一个新用户时的数据PATCH /users/123/validateandPUT /users/123/validate: 验证更新用户 123 时的数据POST /users/batch: 创建多个新用户,PATCH /users/batchandPUT /users/batch: 更新多个用户GET /users/10;11;12: 显示用户 10, 11 和 12 的信息DELETE /users/10;11;12: 删除用户 10, 11 和 12
创建多个新用户时的数据格式:
更新用户 123 和 456 时的数据格式:
Controllers
- ActiveController
- 增加
$searchModelClass查询数据的模型类名,如果不设置,则使用 [[$modelClass]] - 增加
$notFoundMessage模型不存在时的错误信息 - 增加
$allowedCount允许批量执行的资源个数 - 增加
$manyResourcesMessage批量操作请求资源过多的错误信息 - 增加
checkActionAccess($action, $params = [])检查用户是否有执行当前动作的权限 - 增加
checkModelAccess($model, $action, $params = [])检查用户是否有执行数据模型的权限 - 废弃
checkAccess()
- 增加
UrlRule
- 增加
$extraTokens额外的令牌列表。
Actions
修改的 Actions:
- IndexAction
- 增加
afterPrepareDataProvider事件。
- 增加
- ViewAction
- 增加
afterPrepareModel事件。
- 增加
- CreateAction
- 增加
beforeLoadModel事件。 - 增加
afterLoadModel事件。 - 增加
beforeProcessModel事件。 - 增加
afterProcessModel事件。
- 增加
- UpdateAction
- 增加
afterPrepareModel事件。 - 增加
beforeLoadModel事件。 - 增加
afterLoadModel事件。 - 增加
beforeProcessModel事件。 - 增加
afterProcessModel事件。
- 增加
- DeleteAction
- 增加
afterPrepareModel事件。 - 增加
beforeProcessModel事件。 - 增加
afterProcessModel事件。
- 增加
增加的 Actions:
- CreateValidateAction 创建新模型时,验证数据。
beforeLoadModelafterLoadModelbeforeProcessModel
- UpdateValidateAction 更新模型时,验证数据。
afterPrepareModelbeforeLoadModelafterLoadModelbeforeProcessModel
- BatchViewAction 显示多个模型。
afterPrepareModel
- BatchCreateAction 创建多个新模型。
beforeLoadModelafterLoadModelbeforeProcessModelafterProcessModelafterProcessModels
- BatchUpdateAction 更新多个模型。
afterPrepareModelbeforeLoadModelafterLoadModelbeforeProcessModelafterProcessModelafterProcessModels
- BatchDeleteAction 删除多个模型。
afterPrepareModelbeforeProcessModelafterProcessModelafterProcessModels
Events
afterPrepareDataProvider在准备完数据源后触发的事件。afterPrepareModel在准备完模型后触发的事件。beforeLoadModel在模型加载数据前触发的事件,如果返回false,则阻止模型加载数据。afterLoadModel在模型成功加载完数据后触发的事件。beforeProcessModel在处理模型前触发的事件,如果返回false,则阻止处理模型。afterProcessModel在成功处理完模型后触发的事件。afterProcessModels在处理完模型列表后触发的事件。
在批量动作中会多次调用的事件:
afterPrepareModelbeforeLoadModelafterLoadModelbeforeProcessModelafterProcessModel
事件参数说明:
- 事件参数的类型为
ActionEvent。 ActionEvent::$object执行事件时的数据对像,以下列出的是对应事件中的对像类型。afterPrepareDataProvider:\yii\data\ActiveDataProviderafterPrepareModel:\yii\db\ActiveRecordbeforeLoadModel:ArrayafterLoadModel:\yii\db\ActiveRecordbeforeProcessModel:\yii\db\ActiveRecordafterProcessModel:\yii\db\ActiveRecordafterProcessModels:\devzyj\rest\BatchResult
Behaviors
EagerLoadingBehavior需要手动附加到IndexAction,实现了在执行 [[Action::EVENT_AFTER_PREPARE_DATA_PROVIDER]] 事件时,即时加载指定的额外资源。SuppressResponseCodeBehavior需要手动附加到config中的components.response,实现了根据查询参数 [[$suppressResponseCodeParam]],判断是否始终使用200作为 HTTP 状态,并将实际的 HTTP 状态码作为内容的一部分包含在响应中。
All versions of yii2-rest with dependencies
PHP Build Version
Package Version
Requires
yiisoft/yii2 Version
*
The package devzyj/yii2-rest contains the following files
Loading the files please wait ...