src/LosBase/Controller/ORM/AbstractCrudController.php
public function getForm($entityClass = null)
    {
        if (null === $entityClass) {
            $entityClass = $this->getEntityClass();
        }

        $builder = new AnnotationBuilder();
        $form = $builder->createForm($entityClass);

        $hasEntity = false;
        foreach ($form->getElements() as $element) {
            if (method_exists($element, 'setObjectManager')) {
                $element->setObjectManager($this->getEntityManager());
                $hasEntity = true;
            } elseif (method_exists($element, 'getProxy')) {
                $proxy = $element->getProxy();
                if (method_exists($proxy, 'setObjectManager')) {
                    $proxy->setObjectManager($this->getEntityManager());
                    $hasEntity = true;
                }
            }
        }

        if ($hasEntity) {
            $hydrator = new DoctrineHydrator($this->getEntityManager(), $entityClass);
            $form->setHydrator($hydrator);
        } else {
            $form->setHydrator(new ClassMethods());
        }

        $form->add([
            'type' => 'Zend\Form\Element\Csrf',
            'name' => 'csrf',
            'attributes' => [
                'id' => 'csrf',
            ],
        ]);

        $submitElement = new \Zend\Form\Element\Button('submit');
        $submitElement->setAttributes([
            'type' => 'submit',
            'class' => 'btn btn-primary',
        ]);
        $submitElement->setLabel('Salvar');
        $form->add($submitElement, [
            'priority' => -100,
        ]);

        $cancelarElement = new \Zend\Form\Element\Button('cancelar');
        $cancelarElement->setAttributes([
            'type' => 'button',
            'class' => 'btn btn-default',
            'onclick' => 'top.location=\''.$this->url()
                ->fromRoute($this->getActionRoute('list')).'\'',
        ]);
        $cancelarElement->setLabel('Cancelar');
        $form->add($cancelarElement, [
            'priority' => -100,
        ]);

        return $form;
    }
public function getForm($entityClass = null)
    {
        if (null === $entityClass) {
            $entityClass = $this->getEntityClass();
        }

        $builder = new AnnotationBuilder();
        $form = $builder->createForm($entityClass);

        $hasEntity = false;
        foreach ($form->getElements() as $element) {
            if (method_exists($element, 'setObjectManager')) {
                $element->setObjectManager($this->getEntityManager());
                $hasEntity = true;
            } elseif (method_exists($element, 'getProxy')) {
                $proxy = $element->getProxy();
                if (method_exists($proxy, 'setObjectManager')) {
                    $proxy->setObjectManager($this->getEntityManager());
                    $hasEntity = true;
                }
            }
        }

        if ($hasEntity) {
            $hydrator = new DoctrineHydrator($this->getEntityManager(), $entityClass);
            $form->setHydrator($hydrator);
        } else {
            $form->setHydrator(new ClassMethods());
        }

        $form->add([
            'type' => 'Zend\Form\Element\Csrf',
            'name' => 'csrf',
            'attributes' => [
                'id' => 'csrf',
            ],
        ]);

        $submitElement = new \Zend\Form\Element\Button('submit');
        $submitElement->setAttributes([
            'type' => 'submit',
            'class' => 'btn btn-primary',
        ]);
        $submitElement->setLabel('Salvar');
        $form->add($submitElement, [
            'priority' => -100,
        ]);

        $cancelarElement = new \Zend\Form\Element\Button('cancelar');
        $cancelarElement->setAttributes([
            'type' => 'button',
            'class' => 'btn btn-default',
            'onclick' => 'top.location=\''.$this->url()
                ->fromRoute($this->getActionRoute('list')).'\'',
        ]);
        $cancelarElement->setLabel('Cancelar');
        $form->add($cancelarElement, [
            'priority' => -100,
        ]);

        return $form;
    }
public function getForm ( $ entityClass = null ) { if ( null === $ entityClass ) { $ entityClass = $ this -> getEntityClass ( ) ; } $ builder = new AnnotationBuilder ( ) ; $ form = $ builder -> createForm ( $ entityClass ) ; $ hasEntity = false ; foreach ( $ form -> getElements ( ) as $ element ) { if ( method_exists ( $ element , 'setObjectManager' ) ) { $ element -> setObjectManager ( $ this -> getEntityManager ( ) ) ; $ hasEntity = true ; } elseif ( method_exists ( $ element , 'getProxy' ) ) { $ proxy = $ element -> getProxy ( ) ; if ( method_exists ( $ proxy , 'setObjectManager' ) ) { $ proxy -> setObjectManager ( $ this -> getEntityManager ( ) ) ; $ hasEntity = true ; } } } if ( $ hasEntity ) { $ hydrator = new DoctrineHydrator ( $ this -> getEntityManager ( ) , $ entityClass ) ; $ form -> setHydrator ( $ hydrator ) ; } else { $ form -> setHydrator ( new ClassMethods ( ) ) ; } $ form -> add ( [ 'type' => 'Zend\Form\Element\Csrf' , 'name' => 'csrf' , 'attributes' => [ 'id' => 'csrf' , ] , ] ) ; $ submitElement = new \ Zend \ Form \ Element \ Button ( 'submit' ) ; $ submitElement -> setAttributes ( [ 'type' => 'submit' , 'class' => 'btn btn-primary' , ] ) ; $ submitElement -> setLabel ( 'Salvar' ) ; $ form -> add ( $ submitElement , [ 'priority' => - 100 , ] ) ; $ cancelarElement = new \ Zend \ Form \ Element \ Button ( 'cancelar' ) ; $ cancelarElement -> setAttributes ( [ 'type' => 'button' , 'class' => 'btn btn-default' , 'onclick' => 'top.location=\'' . $ this -> url ( ) -> fromRoute ( $ this -> getActionRoute ( 'list' ) ) . '\'' , ] ) ; $ cancelarElement -> setLabel ( 'Cancelar' ) ; $ form -> add ( $ cancelarElement , [ 'priority' => - 100 , ] ) ; return $ form ; }
Retorna a form para o cadastro da entidade.
Retorna a form para o cadastro da entidade .