@@ -49,11 +49,56 @@ class MyModel extends ActiveRecord{
4949## Array Input & Usage At Controller
5050
5151It takes a normal array of POST. This is the example
52+ ``` php
53+ Array (
54+ $_POST['ParentClass'] => ['attr1' => 'value1','attr2' => 'value2'],
55+ // Has One
56+ $_POST['RelatedClass'] => ['relAttr1' => 'value1','relAttr2' => 'value2'],
57+ // Has Many
58+ $_POST['RelatedClass'] => Array
59+ (
60+ [0] => Array
61+ (
62+ [attr1] => value1
63+ [attr2] => value2
64+ )
65+ [1] => Array
66+ (
67+ [attr1] => value1
68+ [attr2] => value2
69+ )
70+ )
71+ )
72+
73+ OR
74+
75+ $_POST['ParentClass'] = Array
76+ (
77+ [attr1] => value1
78+ [attr2] => value2
79+ // has many
80+ [relationName] => Array
81+ (
82+ [0] => Array
83+ (
84+ [relAttr] => relValue1
85+ )
86+ [1] => Array
87+ (
88+ [relAttr] => relValue1
89+ )
90+ )
91+ // has one
92+ [relationName] => Array
93+ (
94+ [relAttr1] => relValue1
95+ [relAttr2] => relValue2
96+ )
97+ );
98+ ```
5299
53100``` php
54101// sample at controller
55- //$_POST['ParentClass'] = ['attr1' => 'value1','attr2' => 'value2'];
56- //$_POST['RelatedClass'][0] = ['attr1' => 'value1','attr2' => 'value2'];
57102if($model->loadAll(Yii:$app->request->post()) && $model->saveAll()){
58103 return $this->redirect(['view', 'id' => $model->id, 'created' => $model->created]);
59104}
@@ -141,32 +186,40 @@ https://github.com/mootensai/yii2-uuid-behavior
141186
142187Add this line to your Model to enable soft delete
143188
144- ` private $_rt_softdelete = ['<column>' => <deleted row marker value>]; `
145-
146- Example :
147-
148- ` private $_rt_softdelete = ['isdeleted' => 1]; `
149-
150- Or :
151-
152- ` private $_rt_softdelete = ['deleted_by' => Yii::app()->user->id] `
153-
154- And add this line to your Model to enable soft restore
155-
156- ` private $_rt_softrestore = ['<column>' => <undeleted row marker value]; `
157-
158- example :
189+ ``` php
190+ private $_rt_softdelete;
191+
192+ function __construct(){
193+ $this->_rt_softdelete = [
194+ '<column >' => <undeleted row marker value >
195+ // multiple row marker column example
196+ 'isdeleted' => 1,
197+ 'deleted_by' => \Yii::$app->user->id,
198+ 'deleted_at' => date('Y-m-d H:i:s')
199+ ];
200+ }
201+ ```
159202
160- ` private $_rt_softrestore = ['isdeleted' => 0]; `
203+ Add this line to your Model to enable soft restore
161204
162- or :
205+ ``` php
206+ private $_rt_softrestore;
207+
208+ function __construct(){
209+ $this->_rt_softrestore = [
210+ '<column >' => <undeleted row marker value >
211+ // multiple row marker column example
212+ 'isdeleted' => 0,
213+ 'deleted_by' => 0,
214+ 'deleted_at' => 'NULL'
215+ ];
216+ }
217+ ```
163218
164- ` private $_rt_softdelete = ['deleted_by' => 0]; `
219+ ### Should work on Yii's supported DB
165220
166- ## Should work on Yii's supported DB
221+ It use all Yii's Active Query or Active Record to execute DB command
167222
168- As it used all Yii's Active Query or Active Record to execute DB command
169-
170223
171224### I'm open for any improvement
172225Please create issue if you got a problem or an idea for enhancement
0 commit comments