PHP code example of kricha / doctrine-audit-bundle

1. Go to this page and download the library: Download kricha/doctrine-audit-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/ */

    

kricha / doctrine-audit-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Kricha\DoctrineAuditBundle\KrichaDoctrineAuditBundle(),
            new BabDev\PagerfantaBundle\BabDevPagerfantaBundle(), // only 

    AuditManager::INSERT
    AuditManager::UPDATE
    AuditManager::DELETE
    AuditManager::ASSOCIATE
    AuditManager::DISSOCIATE

use App\Entity\Order;
use Doctrine\ORM\EntityManagerInterface;
use Kricha\DoctrineAuditBundle\AuditConfiguration;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class TestController extends AbstractController
{
    /**
     * @Route("/")
     */
    public function index(EntityManagerInterface $entityManager, AuditConfiguration $auditConfiguration)
    {
        $auditConfiguration->setUsernameCallable(
            static function () {
                return '[ControllerChanger]';
            }
        );
        $order      = $this->entityManager->find(Order::class, 1);
        $order->setComment(\uniqid());
        $entityManager->persist($order);
        $entityManager->flush();

        return $this->render('index.html.twig', ['hello' => 'wolrd']);
    }
}