I am trying to generate Pdf using KnpSnappyBundle and keep the position in the doctrine when my Bill Entity is generated.
I need a tamplating service for this, which I cannot get inside Entity.
I read in EventListener and tried to get it working.
My config.yml
services:
bill.listener:
class: MyCompany\CompanyBundle\EventListener\BillListener
tags:
- { name: doctrine.event_listener, event: onFlush }
And my listener
namespace MyCompany\CompanyBundle\EventListener;
use Doctrine\ORM\Event\OnFlushEventArgs;
class BillListener
{
public function onFlush(OnFlushEventArgs $args)
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
foreach ($uow->getScheduledEntityInsertions() as $insertions) {
foreach ($insertions as $entity) {
if ($entity instanceof Bill) {
$entity->setFilename("test.pdf");
$md = $em->getClassMetadata(get_class($entity));
$uow->recomputeSingleEntityChangeSet($md, $entity);
}
}
}
}
}
My Bill Entity has a setFilename function where I want to keep the position of the generated bill. But I can't get this to work.
source
share