PHP code example of harp-orm / timestamps

1. Go to this page and download the library: Download harp-orm/timestamps library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

harp-orm / timestamps example snippets


use Harp\Harp\AbstractModel;
use Harp\Timestamps\TimestampsTrait;

class User extends AbstractModel
{
    use TimestampsTrait;

    public static function initialize($config)
    {
        // Adds events to populate the properties
        TimestampsTrait::initialize($config);
    }
}

echo $user->createdAt; // 2014-01-01 00:00:00
echo $user->updatedAt; // 2014-01-01 00:00:00

echo $user->getCreatedAt(); // DateTime object
$user->setCreatedAt(new DateTime());

echo $user->getUpdatedAt(); // DateTime object
$user->setUpdatedAt(new DateTime());

TimestampsTrait::setCurrentDate('2014-03-01 10:00:00');

$user = new User();

echo $user->createdAt; // 2014-03-01 10:00:00
echo $user->updatedAt; // 2014-03-01 10:00:00