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 should I set Creation/Update timestamps

In the documentaion three method for setting timestamps is proposed: behaviours, events and delegating to RDBS (skiping on model).

When we should each of them? May be use together?



51.1k

I suggest you to use behaviors and relay on the application timezone settings, not on database.

    public function initialize()
    {
        $this->addBehavior(new Timestampable(array(
            'beforeValidationOnCreate' => array(
                'field' => 'created_at',
                'format' => 'Y-m-d H:i:s',
            ),
            'beforeValidationOnUpdate' => array(
                'field' => 'updated_at',
                'format' => 'Y-m-d H:i:s',
            ),
        )));
    }