Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace NominaEntity;
- use DoctrineCommonCollectionsArrayCollection;
- use DoctrineORMMapping as ORM;
- use ZendFormAnnotation;
- use NominaEntityEmpleadosDetalles;
- /**
- * Empleado
- *
- * @ORMTable(name="empleado")
- * @ORMEntity
- * @AnnotationHydrator("ZendStdlibHydratorObjectProperty")
- * @AnnotationName("EmpleadoForm")
- */
- class Empleado
- {
- /**
- * @var integer
- *
- * @ORMColumn(name="id", type="integer", nullable=false)
- * @ORMId
- * @ORMGeneratedValue(strategy="IDENTITY")
- */
- private $id;
- /**
- * @var string
- *
- * @ORMColumn(name="nombre", type="string", length=255, nullable=false)
- * @AnnotationType("ZendFormElementText")
- * @AnnotationRequired({"required":"true"})
- * @AnnotationFilter({"name":"StripTags"})
- * @AnnotationOptions({"label":"Nombre"})
- * @AnnotationAttributes({"class":"form-control"})
- * @AnnotationValidator({"name":"NotEmpty","options":{"messages":{"isEmpty":"no debe estar vacio"}}})
- */
- private $nombre;
- /**
- * @var EmpleadosDetalles $detalles
- * @ORMOneToMany(targetEntity="NominaEntityEmpleadosDetalles", mappedBy="empleado", cascade={"persist"})
- * @AnnotationComposedObject("NominaEntityEmpleadosDetalles")
- */
- private $detalles;
- /**
- * @AnnotationType("ZendFormElementSubmit")
- * @AnnotationAttributes({"value":"Procesar"})
- * @AnnotationAttributes({"class":"btn btn-primary"})
- */
- public $submit;
- public function __construct() {
- $this->detalles = new ArrayCollection();
- }
- public function getDetalles() {
- return $this->detalles;
- }
- /**
- * Set nombre
- *
- * @param string $nombre
- * @return Empleado
- */
- public function setNombre($nombre)
- {
- $this->nombre = $nombre;
- return $this;
- }
- /**
- * Get nombre
- *
- * @return string
- */
- public function getNombre()
- {
- return $this->nombre;
- }
- }
- <?php
- namespace NominaEntity;
- use DoctrineORMMapping as ORM;
- use ZendFormAnnotation;
- /**
- * EmpleadosDetalles
- *
- * @ORMTable(name="empleadosDetalles", indexes={@ORMIndex(name="fk_empleado", columns={"idEmpleado"})})
- * @ORMEntity
- * @AnnotationHydrator("ZendStdlibHydratorObjectProperty")
- * @AnnotationName("EmpleadoDetallesForm")
- */
- class EmpleadosDetalles
- {
- /**
- * @var integer
- *
- * @ORMColumn(name="id", type="integer", nullable=false)
- * @ORMId
- * @ORMGeneratedValue(strategy="IDENTITY")
- */
- private $id;
- /**
- * @var string
- *
- * @ORMColumn(name="salario", type="int", nullable=false)
- * @AnnotationType("ZendFormElementText")
- * @AnnotationRequired({"required":"true"})
- * @AnnotationFilter({"name":"StripTags"})
- * @AnnotationOptions({"label":"Salario"})
- * @AnnotationAttributes({"class":"form-control"})
- * @AnnotationValidator({"name":"NotEmpty","options":{"messages":{"isEmpty":"no debe estar vacio"}}})
- */
- private $salario = '0';
- /**
- * @var string
- *
- * @ORMColumn(name="numero", type="string", length=20, nullable=true)
- * @AnnotationType("ZendFormElementText")
- * @AnnotationRequired({"required":"true"})
- * @AnnotationFilter({"name":"StripTags"})
- * @AnnotationOptions({"label":"Numero"})
- * @AnnotationAttributes({"class":"form-control"})
- * @AnnotationValidator({"name":"NotEmpty","options":{"messages":{"isEmpty":"no debe estar vacio"}}})
- */
- private $numero;
- /**
- * @ORMColumn(name="idEmpleado", type="integer", length=11, nullable=false)
- */
- private $idEmpleado;
- /**
- * @ORMManyToOne(targetEntity="NominaEntityEmpleado", inversedBy="detalles")
- * @ORMJoinColumns({
- * @ORMJoinColumn(name="idEmpleado", referencedColumnName="id")
- * })
- */
- protected $empleado;
- /**
- * Set salario
- *
- * @param integer $salario
- * @return EmpleadosDetalles
- */
- public function setSalario($salario)
- {
- $this->salario = $salario;
- return $this;
- }
- /**
- * Get salario
- *
- * @return integer
- */
- public function getSalario()
- {
- return $this->salario;
- }
- /**
- * Set numero
- *
- * @param string $numero
- * @return EmpleadosDetalles
- */
- public function setNumero($numero)
- {
- $this->numero = $numero;
- return $this;
- }
- /**
- * Get numero
- *
- * @return string
- */
- public function getNumero()
- {
- return $this->numero;
- }
- public function setEmpleado(Empleado $empleado)
- {
- $this->empleado = $empleado;
- return $this;
- }
- public function getEmpleado()
- {
- return $this->empleado;
- }
- }
- public function addAction() {
- $view = new ViewModel();
- $empleado = new Empleado();
- $entityManager = $this->entityManager();
- $builder = new DoctrineAnnotationBuilder($entityManager);
- $form = $builder->createForm($empleado);
- $request = $this->getRequest();
- if ($request->isPost()) {
- $form->bind($empleado);
- $form->setHydrator(new DoctrineHydrator($entityManager,'NominaEntityEmpleado'));
- $form->setValidationGroup('nombre');
- $form->setData($request->getPost());
- if ($form->isValid()) {
- $entityManager->persist($empleado);
- $entityManager->flush();
- $this->redirect()->toRoute('empleado');
- } else {
- $view->messages = $form->getMessages();
- }
- }
- $view->form = $form;
- return $view;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement