We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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);
    }

}


98.9k
Accepted
answer

You can read people's mind! Awesome!