This repository has been archived by the owner on Feb 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
readme_en.txt
87 lines (68 loc) · 1.75 KB
/
readme_en.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
ETrashBinBehavior
=================
Adds an ability to mark model as deleted and restore it when needed.
Installing and configuring
--------------------------
### Preparing model
There should be an attribute in the model to store deletion flag. For example, "is_removed".
### Attaching behavior
~~~php
<?php
function behaviors()
{
return array(
'trash'=>array(
'class'=>'ext.yiiext.behaviors.model.trashBin.ETrashBinBehavior',
// Deletion flag table column name (required)
'trashFlagField'=>'is_removed',
// Value that is written to $trashFlagField when model is deleted
// Default is 1
'removedFlag'=>1,
// Value that is written to $trashFlagField when model is restored
// Default is 0
'restoredFlag'=>0,
),
);
}
~~~
### Requirements
[Yii Framework 1.1.4](http://www.yiiframework.com/)
API
---
### remove()
Mark model as deleted.
~~~php
<?php
$user=User::model()->findByPk(1);
$user->remove();
$user->save();
~~~
### restore()
Restore deleted model.
~~~php
<?php
// Since deleted models are ignored by default we have to show all models:
User::model()->withRemoved();
// or just turn off behavior completely
User::model()->disableBehavior('trash');
$user=User::model()->findByPk(1);
// if you turned behavior off, don't forget to turn it back on
User::model()->enableBehavior('trash');
$user->restore();
$user->save();
~~~
### getIsRemoved()
Tells if model is marked as deleted.
~~~php
<?php
$user1=User::model()->withRemoved()->findByPk(1);
echo $user1->getIsRemoved() ? 'status=removed' : 'status=normal';
$user2=User::model()->withRemoved()->findByPk(2);
echo $user2->isRemoved ? 'status=removed' : 'status=normal';
~~~
### withRemoved()
Allows to search for deleted models.
~~~php
<?php
$users=User::model()->withRemoved()->findAll();
~~~