PHP code example of tourze / doctrine-track-bundle
1. Go to this page and download the library: Download tourze/doctrine-track-bundle 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/ */
use Doctrine\ORM\Mapping as ORM;
use Tourze\DoctrineTrackBundle\Attribute\TrackColumn;
#[ORM\Entity]
class User
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[TrackColumn] // This field will be tracked
#[ORM\Column]
private string $email;
#[TrackColumn] // This field will be tracked
#[ORM\Column]
private string $username;
#[ORM\Column] // This field will NOT be tracked
private \DateTime $lastLogin;
// ... getters and setters
}
use Tourze\DoctrineTrackBundle\Entity\EntityTrackLog;
// Find all changes to a specific entity
$logs = $entityManager->getRepository(EntityTrackLog::class)->findBy([
'objectClass' => User::class,
'objectId' => '123'
]);
// Find all changes by a specific action
$createLogs = $entityManager->getRepository(EntityTrackLog::class)->findBy([
'action' => 'create'
]);
#[ORM\Entity]
class MyEntity
{
#[ORM\Id] // Required for tracking
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
// ... other properties
}