Answer the question
In order to leave comments, you need to log in
Symfony ChoicesType?
Hello.
Guys, how can I load my categories in choicestype?
$builder->add('category_id', ChoiceType::class, [
'choices' =>$this->getCategory(),
'by_reference' => false,
'placeholder' => 'Выбрать категорию',
'required' => false,
'label' => 'Категория',
]);
public function getCategory(){
$w = new \Doctrine\ORM\EntityRepository;
return $w->get('doctrine')->getRepository(\Backend\Modules\Asaf\Domain\Categorys\Category::class)->getAllCategoryActive(true);
}
Answer the question
In order to leave comments, you need to log in
Given that the field is called 'category_id', I dare to assume that you have it associated with Many-to-One or Many-to-Many. In this case you need to use not ChoiceType but EntityType .
And an example of how to select only part of the categories:
https://symfony.com/doc/current/reference/forms/ty...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question