https://github.com/denq/yii2-record-replacer
Record replacer a component for safe add new records or replacing that already exists
https://github.com/denq/yii2-record-replacer
Last synced: about 1 year ago
JSON representation
Record replacer a component for safe add new records or replacing that already exists
- Host: GitHub
- URL: https://github.com/denq/yii2-record-replacer
- Owner: DenQ
- License: mit
- Created: 2015-12-01T16:44:14.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-12T14:18:46.000Z (over 10 years ago)
- Last Synced: 2024-11-25T00:14:54.023Z (over 1 year ago)
- Language: PHP
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yii2-recod-replacer
Record replacer a component for safe add new records or replacing that already exists
# Install
```sh
composer require "denq/yii2-record-replacer"
```
# Configure
```php
'components' => [
'RecordReplacer' => [
'class' => 'RecordReplacer\RecordReplacer',
],
...
]
```
# Usage
```php
Yii::$app->RecordReplacer->Run($model, $fields, $primary)
```
* $model
* type: \yii\db\ActiveRecord
* description: your active record model
* required: true
* $fields
* type: array
* description: array with fields and values
* required: true
* $primary
* type: array
* description: searchable fields
* required: false
* default value: []
# Example
```php
Yii::$app->RecordReplacer->Run(new CustomModel, [
'field_1' => 'val 1',
'field_2' => 'val 2',
...
'field_n' => 'val n',
], [
'field_n'
]);
```