1 <?php
2 3 4 5 6 7 8 9
10
11 12 13 14 15 16 17
18 class P3JSONBehavior extends CActiveRecordBehavior {
19
20 public function beforeSave($event) {
21 foreach($this->Owner->attributes AS $key => $value) {
22 if(is_array($this->Owner->attributes[$key]))
23 $this->Owner->$key = CJSON::encode($value);
24 }
25 }
26
27 public function afterFind($event) {
28 foreach($this->Owner->attributes AS $key => $value) {
29 if (CJSON::decode($value))
30 $this->Owner->$key = CJSON::decode($value);
31 }
32 }
33
34 }
35 ?>
36