Created
June 2, 2016 20:23
-
-
Save davialexandre/e3992f3ac165a588cf01aa1092070c6f to your computer and use it in GitHub Desktop.
Using getRepository on a FormType
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Form\Type; | |
use Doctrine\Common\Persistence\ObjectManager; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
class NomeDoSeuTypeType extends AbstractType | |
{ | |
/** | |
* @var ObjectManager | |
*/ | |
private $objectManager; | |
public function __construct(ObjectManager $objectManager) | |
{ | |
$this->objectManager = $objectManager; | |
} | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder->addEventListener( | |
FormEvents::PRE_SUBMIT, | |
function(FormEvent $event) { | |
... | |
$this-objectManager->getRepository('YourEntity') | |
... | |
} | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.form.type.nome_do_seu_type: | |
class: AppBundle\Form\Type\NomeDoSeuTypeType | |
arguments: ['@doctrine.orm.entity_manager'] | |
tags: | |
- { name: form.type, alias: nome_do_seu_type } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment