Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to elegantly transform field in Model.

Hi, I have some Models which one of its field is a json data. My question is, how to elegantly transform the json data after the models being fetched? Is there somekind of afterFetch event?

class Settings extends \Phalcon\MVC\Model
{
    $public $id;
    $public $name,
    $public $value; //json data

    public function beforeSave(){
        $this->value = json_encode($this->value);
    }

    //is there any kind of event like this??? 
    public function afterFetch(){
        $this->value  = json_decode($this->value,true);
    }

}


84.5k
Accepted
answer

You can read people's mind! Awesome!