Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SF][Symfony][SF4) Listener - problem obsługi w IF wartości z formularza: 0 (zero), jak w IF obsłużyć wartość 0 z formularza ?
damianooo
post 26.11.2022, 13:25:27
Post #1





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

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


Nie wiem czemu mój listener nie reaguje na podanie w formularzu 0 (zera).
Wylogowałem sobie jaką wartość dostaję i mam INTEGER 0 (zero) .
Nie wiem czemu kod nie wchodzi w tego elseif-a pierwszego , tylko w tego drugiego.
Będę wdzięczny za podpowiedź.



services.yaml

  1.  
  2. App\EventListener\ResultListener:
  3. tags:
  4. - { name: doctrine.event_listener, event: postUpdate }


ResultListener

  1. class ResultListener {
  2.  
  3. ...
  4.  
  5. public function postUpdate(LifecycleEventArgs $args) {
  6. $entity = $args->getEntity();
  7. $em = $args->getEntityManager();
  8.  
  9. if ($entity instanceof Meet) {
  10.  
  11. $meetId = $entity->getId();
  12. $typeRepo = $em->getRepository(Type::class);
  13. $types = $typeRepo->findByMeet($meetId);
  14.  
  15. foreach ($types as $type) {
  16.  
  17. ...
  18.  
  19. elseif (
  20. // typ1 == typ2 i wynik1 == wynik2 i typ1 <> wynik1
  21. ($type->getHostType() == $type->getGuestType()) &&
  22. ($entity->getHostGoals() == $entity->getGuestGoals()) &&
  23. ($type->getHostType() <> $entity->getHostGoals()) &&
  24. (!empty($entity->getHostGoals()) && !empty($entity->getGuestGoals()))
  25. )
  26. {
  27. $this->logger->info('Update set 2 points (option 3)');
  28. $type->setNumberOfPoints(2);
  29. }
  30.  
  31. elseif (
  32. empty($entity->getHostGoals()) ||
  33. empty($entity->getGuestGoals())
  34. )
  35. {
  36. $this->logger->info('@@@@@@@@@@ $entity->getHostGoals(): ' . $entity->getHostGoals());
  37. $this->logger->info('@@@@@@@@@@ $entity->getGuestGoals(): ' . $entity->getGuestGoals());
  38. $this->logger->info('@@@@@@@@@@ empty($entity->getHostGoals()): ' . empty($entity->getHostGoals()));
  39. $this->logger->info('@@@@@@@@@@ empty($entity->getGuestGoals()): ' . empty($entity->getGuestGoals()));
  40. $this->logger->info('@@@@@@@@@@ gettype($entity->getHostGoals()): ' . gettype($entity->getHostGoals()));
  41. $this->logger->info('@@@@@@@@@@ NO UPDATE!');
  42. }
  43.  
  44. ...




co to dostaję w logach:

[2022-11-26 12:45:02] app.INFO: @@@@@@@@@@ $entity->getHostGoals(): 0 [] []
[2022-11-26 12:45:02] app.INFO: @@@@@@@@@@ $entity->getGuestGoals(): 0 [] []
[2022-11-26 12:45:02] app.INFO: @@@@@@@@@@ empty($entity->getHostGoals()): 1 [] []
[2022-11-26 12:45:02] app.INFO: @@@@@@@@@@ empty($entity->getGuestGoals()): 1 [] []
[2022-11-26 12:45:02] app.INFO: @@@@@@@@@@ gettype($entity->getHostGoals()): integer [] []
[2022-11-26 12:45:02] app.INFO: @@@@@@@@@@ NO UPDATE! [] []




Go to the top of the page
+Quote Post

Posty w temacie


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: 5.06.2024 - 02:17