Skip to content

Commit

Permalink
Update readme for input POST array and
Browse files Browse the repository at this point in the history
update on how to use soft delete & soft restore
  • Loading branch information
mootensai committed Sep 28, 2017
1 parent 6bb4ee9 commit 65e4823
Showing 1 changed file with 76 additions and 23 deletions.
99 changes: 76 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,56 @@ class MyModel extends ActiveRecord{
## Array Input & Usage At Controller

It takes a normal array of POST. This is the example
```php
Array (
$_POST['ParentClass'] => ['attr1' => 'value1','attr2' => 'value2'],
// Has One
$_POST['RelatedClass'] => ['relAttr1' => 'value1','relAttr2' => 'value2'],
// Has Many
$_POST['RelatedClass'] => Array
(
[0] => Array
(
[attr1] => value1
[attr2] => value2
)
[1] => Array
(
[attr1] => value1
[attr2] => value2
)
)
)

OR

$_POST['ParentClass'] = Array
(
[attr1] => value1
[attr2] => value2
// has many
[relationName] => Array
(
[0] => Array
(
[relAttr] => relValue1
)
[1] => Array
(
[relAttr] => relValue1
)
)
// has one
[relationName] => Array
(
[relAttr1] => relValue1
[relAttr2] => relValue2
)
);
```

```php
// sample at controller
//$_POST['ParentClass'] = ['attr1' => 'value1','attr2' => 'value2'];
//$_POST['RelatedClass'][0] = ['attr1' => 'value1','attr2' => 'value2'];
if($model->loadAll(Yii:$app->request->post()) && $model->saveAll()){
return $this->redirect(['view', 'id' => $model->id, 'created' => $model->created]);
}
Expand Down Expand Up @@ -141,32 +186,40 @@ https://github.com/mootensai/yii2-uuid-behavior

Add this line to your Model to enable soft delete

`private $_rt_softdelete = ['<column>' => <deleted row marker value>];`

Example :

`private $_rt_softdelete = ['isdeleted' => 1];`

Or :

`private $_rt_softdelete = ['deleted_by' => Yii::app()->user->id]`

And add this line to your Model to enable soft restore

`private $_rt_softrestore = ['<column>' => <undeleted row marker value];`

example :
```php
private $_rt_softdelete;

function __construct(){
$this->_rt_softdelete = [
'<column>' => <undeleted row marker value>
// multiple row marker column example
'isdeleted' => 1,
'deleted_by' => \Yii::$app->user->id,
'deleted_at' => date('Y-m-d H:i:s')
];
}
```

`private $_rt_softrestore = ['isdeleted' => 0];`
Add this line to your Model to enable soft restore

or :
```php
private $_rt_softrestore;

function __construct(){
$this->_rt_softrestore = [
'<column>' => <undeleted row marker value>
// multiple row marker column example
'isdeleted' => 0,
'deleted_by' => 0,
'deleted_at' => 'NULL'
];
}
```

`private $_rt_softdelete = ['deleted_by' => 0];`
### Should work on Yii's supported DB

## Should work on Yii's supported DB
It use all Yii's Active Query or Active Record to execute DB command

As it used all Yii's Active Query or Active Record to execute DB command


### I'm open for any improvement
Please create issue if you got a problem or an idea for enhancement
Expand Down

0 comments on commit 65e4823

Please sign in to comment.