Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony4][SF4][SF] Sortowanie danych na liście rozwijalnej formularza
damianooo
post 6.10.2022, 23:01:50
Post #1





Grupa: Zarejestrowani
Postów: 493
Pomógł: 2
Dołączył: 15.07.2011
Skąd: Katowice

Ostrzeżenie: (0%)
-----


Próbuję posortować dane (lista zespołów piłkarskich) w polu (lista rozwijalna) formularza dla Meet (spotkania)
Sortowanie ma być po id ligi (league)

Encja Meet jest powiązana relacją z encją Team:

  1. /**
  2.   * @ORM\ManyToOne(targetEntity="App\Entity\Team")
  3.   * @ORM\JoinColumn(nullable=false)
  4.   */
  5. private $hostTeam;


A encja Team z encją League:
  1. /**
  2.   * @ORM\ManyToOne(targetEntity="App\Entity\League", inversedBy="teams")
  3.   * @ORM\JoinColumn(nullable=false)
  4.   */
  5. private $league;



Kod formularza :

  1. class MeetType extends AbstractType
  2. {
  3. public function buildForm(FormBuilderInterface $builder, array $options)
  4. {
  5. $builder
  6. ->add('name' , null, ['label' => 'Nazwa'])
  7. ->add('hostGoals' , null, ['label' => 'Bramki gospodarz'])
  8. ->add('guestGoals' , null, ['label' => 'Bramki gość'])
  9. ->add('term' , null, ['label' => 'Termin meczu'])
  10. ->add('position' , null, ['label' => 'Pozycja meczu'])
  11. ->add('hostTeam' , null, ['label' => 'Gospodarz'])
  12.  
  13. ->add('hostTeam', EntityType::class, [
  14. 'class' => Team::class,
  15. 'query_builder' => function (EntityRepository $er) {
  16. return $er->createQueryBuilder('t')
  17. ->innerJoin('t.league', 'l')
  18. ->orderBy('l.id', 'ASC');
  19. },
  20. 'label' => 'Gospodarz',
  21. ])



Mam taki błąd:

Argument 1 passed to App\Form\MeetType::App\Form\{closure}() must be an instance of App\Form\EntityRepository, instance of App\Repository\TeamRepository given, called in C:\xampp\htdocs\ligatyperow2\vendor\symfony\doctrine-bridge\Form\Type\EntityType.php on line 32


Mogę prosić o podpowiedź co mam źle ?

PS. Sortowanie na razie może być po czymkolwiek bylebym wiedział co mam źle w obecnej implementacji kodu.



Go to the top of the page
+Quote Post
ohm
post 7.10.2022, 08:44:36
Post #2





Grupa: Zarejestrowani
Postów: 618
Pomógł: 143
Dołączył: 22.12.2010

Ostrzeżenie: (0%)
-----


Wg błędu musisz dodać use dla EntityRepository, bodajże
  1. use Doctrine\ORM\EntityRepository;
Go to the top of the page
+Quote Post
Salvation
post 7.10.2022, 10:34:19
Post #3





Grupa: Zarejestrowani
Postów: 338
Pomógł: 70
Dołączył: 15.07.2014

Ostrzeżenie: (0%)
-----


To co wyżej, to może być dobry kierunek. Jak zaimportowałeś klasę `EntityRepository` w swojej MeetType::class?
Go to the top of the page
+Quote Post
damianooo
post 7.10.2022, 19:58:36
Post #4





Grupa: Zarejestrowani
Postów: 493
Pomógł: 2
Dołączył: 15.07.2011
Skąd: Katowice

Ostrzeżenie: (0%)
-----


no fakt , dzięki za podpowiedź.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 23:43