Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 724 Bytes

timestampable.md

File metadata and controls

43 lines (30 loc) · 724 Bytes

Timestampable

Entity

<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;

/**
 * @ORM\Entity
 */
class Category implements TimestampableInterface
{
    use TimestampableTrait;
}

Usage

<?php

use App\Entity\Category;   

/** @var Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface $category */
$category = new Category();

$entityManager->persist($category);
$entityManager->flush();

var_dump($category->getCreatedAt());
// instanceof "DateTime"

var_dump($category->getUpdatedAt());
// instanceof "DateTime"