PHP code example of mpalourdio / mpa-custom-doctrine-hydrator

1. Go to this page and download the library: Download mpalourdio/mpa-custom-doctrine-hydrator 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/ */

    

mpalourdio / mpa-custom-doctrine-hydrator example snippets


$builder       = new \MpaCustomDoctrineHydrator\Form\Annotation\AnnotationBuilder($this->entityManager, $this->formElementManager);
$form = $builder->createForm('Application\Entity\Myentity');

$form = $this->sm->get('annotationbuilder')->createForm('Application\Entity\Myentity');

$hydrator = $this->sm->get('hydrator')->setEntity('Application\Entity\Myentity');
$form->setHydrator($hydrator);

$hydrator = $this->sm->get('hydrator')->setEntity('Application\Entity\Myentity');
$form->setHydrator($hydrator);


$this->add(
            [
                'name'       => 'mydate',
                'type'       => 'MpaCustomDoctrineHydrator\Form\Element\Date',
                'attributes' => [
                    'id'    => 'mydate',
                ],
                'options'    => [
                    'label'  => 'My date',
                    'format' => 'd/m/Y' // format needed
                ],
            ]
        );

$this->add(
            [
                'name'       => 'mydate',
                'type'       => 'Date',
                'attributes' => [
                    'id'    => 'mydate',
                ],
                'options'    => [
                    'label'  => 'My date',
                ],
            ]
        );

public function getInputFilterSpecification()
{
        $filters = [
            'otherdate' => [
                'filters' => [
                    [
                        'name' => 'MpaCustomDoctrineHydrator\Filter\DateToDateTime',
                        'options' => [
                            'format' => 'd/m/Y' ('date_format' key is also accepted)
                        ]
                    ],
                ],
            ],
        ];
        return $filters;
}

public function getInputFilterSpecification()
{
        $filters = [
            'otherdate' => [
                'filters' => [
                    [
                        'name' => 'DateToDateTime',
                    ], // no options needed here, would be ignored anyway
                ],
            ],
        ];
        return $filters;
}

$this->getFormFactory()->getFormElementManager()->setServiceLocator($this->sm);

$plugins = $this->sm ->get('FilterManager');
$chain   = new FilterChain;
$chain->setPluginManager($plugins);
$myForm->getFormFactory()->getInputFilterFactory()->setDefaultFilterChain($chain);