Ver Mensaje Individual
  #5 (permalink)  
Antiguo 13/04/2015, 11:09
Avatar de anacona16
anacona16
 
Fecha de Ingreso: marzo-2010
Ubicación: Bogota DC
Mensajes: 610
Antigüedad: 14 años, 1 mes
Puntos: 52
Respuesta: Configurar Entity listeners de Doctrine en Symfony 2.6

Hola hhs

Esta es la entidad:

Código PHP:
Ver original
  1. <?php
  2.  
  3. namespace AppBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6.  
  7. /**
  8.  * DetalleGrupo
  9.  *
  10.  * @ORM\Table(name="tb_productos")
  11.  * @ORM\Entity(repositoryClass="AppBundle\Repository\ProductoRepository")
  12.  * @ORM\EntityListeners({"AppBundle\EntityListeners\ProductoListener"})
  13.  */
  14. class Producto
  15. {
  16.     /**
  17.      * @var integer
  18.      *
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="bigint")
  22.      */
  23.     private $id;
  24.  
  25.     /**
  26.      * @var string
  27.      *
  28.      * @ORM\Column(type="string", length=100, nullable=false)
  29.      */
  30.     private $nombre;
  31.  
  32.     /**
  33.      * Get id
  34.      *
  35.      * @return integer
  36.      */
  37.     public function getId()
  38.     {
  39.         return $this->id;
  40.     }
  41.  
  42.     /**
  43.      * Set nombre
  44.      *
  45.      * @param string $nombre
  46.      * @return Colegio
  47.      */
  48.     public function setNombre($nombre)
  49.     {
  50.         $this->nombre = $nombre;
  51.  
  52.         return $this;
  53.     }
  54.  
  55.     /**
  56.      * Get nombre
  57.      *
  58.      * @return string
  59.      */
  60.     public function getNombre()
  61.     {
  62.         return $this->nombre;
  63.     }
  64. }

Y esta es la clase listener:

Código PHP:
Ver original
  1. <?php
  2.  
  3. namespace AppBundle\EntityListeners;
  4.  
  5. use AppBundle\Entity\Producto;
  6. use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
  7.  
  8. class ProductoListener
  9. {
  10.     public function postPersist(Producto $producto, LifecycleEventArgs $lifecycleEventArgs) {
  11.         ldd($producto->getId());
  12.     }
  13. }

Segun la doc de Doctrine http://docs.doctrine-project.org/pro...tity-listeners, todo estaria bien.

Gracias por tu ayuda.
__________________
Aprendiendo!!!