File tree Expand file tree Collapse file tree 1 file changed +36
-1
lines changed
Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,13 @@ class EasyModel extends Model
6565 */
6666 public $ returnAs = 'object ' ;
6767
68+ /**
69+ * Protected fields
70+ *
71+ * @var array
72+ */
73+ public $ protected = [];
74+
6875 /**
6976 * Construct the CI_Model
7077 */
@@ -416,6 +423,25 @@ public function getRowResult($query, $last = false)
416423 return $ query ->{$ mode }('object ' );
417424 }
418425
426+ /**
427+ * Protect fields by removing them from $row
428+ *
429+ * @param array|object $row
430+ * @return mixed
431+ */
432+ public function protectFields ($ row )
433+ {
434+ foreach ($ this ->protected as $ attr ) {
435+ if (is_object ($ row )) {
436+ unset($ row ->$ attr );
437+ } else {
438+ unset($ row [$ attr ]);
439+ }
440+ }
441+
442+ return $ row ;
443+ }
444+
419445 /**
420446 * Grabs data from a table
421447 * OR a single record by passing $id,
@@ -750,8 +776,17 @@ public function saveOnly($data, $show = false)
750776 */
751777 public function create ($ data )
752778 {
779+
780+
753781 $ this ->db ->set ($ data )->insert ($ this ->table );
754- return $ this ->selectLast ('* ' );
782+
783+ $ data = $ this ->selectLast ('* ' );
784+
785+ if (!empty ($ this ->protected )) {
786+ return $ this ->protectFields ($ data );
787+ }
788+
789+ return $ data ;
755790 }
756791
757792 /**
You can’t perform that action at this time.
0 commit comments