Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SF][Symfony2][SF2] LoggerInterface problem, Logger w klasie Repository
damianooo
post 13.07.2022, 22:13:48
Post #1





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

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


Próbowałem wylogować sobie coś w klasie Repozytorium i mam taki błąd:

[2022-07-11 23:52:02] console.ERROR: Error thrown while running command "app:przypominajka". Message: "Call to a member function info() on null" {"exception":"[object] (Error(code: 0): Call to a member function info() on null at /home/dcpl/domains/test.o10.pl/src/Repository/TypeRepository.php:267)","command":"app:przypominajka","message":"Call to a member function info() on null"} []

Klasa TypeRepository :

  1. namespace App\Repository;
  2.  
  3. use App\Entity\Type;
  4. use App\Entity\User;
  5. use App\Entity\Meet;
  6. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. use Psr\Log\LoggerInterface;
  9.  
  10. /**
  11.  * @method Type|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method Type|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method Type[] findAll()
  14.  * @method Type[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class TypeRepository extends ServiceEntityRepository
  17. {
  18. private $loggger;
  19.  
  20. public function __construct(ManagerRegistry $registry, LoggerInterface $logger)
  21. {
  22. parent::__construct($registry, Type::class);
  23. $this->loggger = $logger;
  24. }
  25.  
  26. ....
  27.  
  28.  
  29. public function getNoTypedUsersList($matchday) {
  30.  
  31. // Pobranie listy telefonów użytkowników, którzy jeszcze nie podali typów
  32. $sql = 'SELECT u.phone, u.id '
  33. . 'FROM type t '
  34. . 'INNER JOIN user u ON t.user_id = u.id '
  35. . 'INNER JOIN meet m ON t.meet_id = m.id '
  36. . 'INNER JOIN matchday md ON m.matchday_id = md.id '
  37. . 'WHERE md.id = :matchday '
  38. . 'AND u.status = 1 '
  39. . 'GROUP BY u.id '
  40. . 'HAVING COUNT(t.user_id) > 0 ';
  41. $params = array('matchday' => $matchday);
  42. $userTypes = $this->getEntityManager()->getConnection()->executeQuery($sql, $params)->fetchAll();
  43.  
  44. // Pobieram wszystkich aktywnych użytkowników
  45. $userRepo = $this->getEntityManager()->getRepository(User::class);
  46. $users = $userRepo->findByStatus(1);
  47.  
  48. $this->logger->info('DC $users: ' . $users);




Wskazana w logu z błędem linia 267 to :

$this->logger->info('DC $users: ' . $users);
w powyższej metodzie getNoTypedUsersList


nie wiem czy źle wstrzyknąłem LoggerInterface ?


Go to the top of the page
+Quote Post
viking
post 14.07.2022, 05:34:17
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


$this->loggger 3 g potem się odwołujesz do logger


--------------------
Go to the top of the page
+Quote Post
Salvation
post 14.07.2022, 09:23:10
Post #3





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

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


Logger jest nullerm z jakiegoś powodu.
"Powiedziałeś" Symfony, że to Service? W 2 z tego co pamiętam, nie ma autowire'ingu, więc musisz jawnie przekazać klasę do swojego Repository.
Go to the top of the page
+Quote Post
damianooo
post 14.07.2022, 15:24:58
Post #4





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

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


Viking miał rację ... miałem literówkę : loggger zamiast logger.

Dzięki.
Go to the top of the page
+Quote Post
Salvation
post 14.07.2022, 19:03:04
Post #5





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

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


Czego używasz do kodowania, że IDE / Edytor tego nie wyłapał?
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: 27.04.2024 - 15:38