Ray Kootstra Ray Kootstra - 14 days ago 72 0

Example how to make a created_on and updated_on column in your entity thats is automatically filled by Gedmo.

PHP

Symfony2 Doctrine2 Gedmo timestampable

<?php

namespace My\ApplicationBundle\Entity\Traits;

use DateTime;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * Class Timestampable
 */
trait Timestampable
{
    /**
     * @var DateTime
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(name="created_on", type="datetime", nullable=false)
     */
    protected $createdOn;

    /**
     * @var DateTime
     * @Gedmo\Timestampable(on="update")
     * @ORM\Column(name="updated_on", type="datetime", nullable=false)
     */
    protected $updatedOn;


    /**
     * @inheritdoc
     */
    public function getCreatedOn()
    {
        return $this->createdOn;
    }


    /**
     * @inheritdoc
     */
    public function getUpdatedOn()
    {
        return $this->updatedOn;
    }
}
Comments