Here is my problem. I am using the buildForm method for symfony 2.1 to create my form. Everything works fine with the following code:
$builder->add('combat','entity',array( class' => 'KarateCompetitionBundle:CompetitionCombat', 'empty_value' => 'Sélectionner un combat'));
But I want to filter and display only some Combat . Therefore, I have to use the query_builder parameter. When I do this, I get an error message This value is not valid . Here is the code:
$builder->add('combat','entity',array( 'class' => 'KarateCompetitionBundle:CompetitionCombat', 'empty_value' => 'Sélectionner un combat', 'query_builder' => function(CombatRepository $cr) { return $cr->getAllWithoutBilanQueryBuilder();}));
I cut at least the code (i.e. does not filter the getAllWithoutBilanQueryBuilder method) to find the problem.
public function getAllWithoutBilanQueryBuilder(){ $queryBuilder = $this->getEntityManager()->createQueryBuilder(); return $queryBuilder->select('c')->from('KarateEntrainementBundle:CompetitionCombat', 'c');
}
I compared both generations of HTML in each case, and they are the same.
I put a var_dump($object) on the controller after binding the form with the request $form->bind($request) and it turned out that when I use the query_builder parameter, Combat is null until it is null unless I use it .
I can’t understand why? I found several posts on the Internet with the same problem, but with none of them. Is it possible that there is a problem with symfony here or am I doing something wrong?
source share