Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony]Automatic Service Loading
Lirdoner
post 21.07.2017, 14:02:10
Post #1





Grupa: Zarejestrowani
Postów: 500
Pomógł: 1
Dołączył: 29.09.2009

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


Cześć, mam problem z automatycznym ładowaniem serwisu. Zgodnie z dokumentacją: http://symfony.com/doc/current/service_container.html wystarczy, że utworzę klasę i nie muszę jej już nigdzie konfigurować. No więc zrobiłem klasę:
  1. <?php
  2.  
  3. namespace AppBundle\Model;
  4.  
  5. use Doctrine\ORM\EntityManagerInterface;
  6.  
  7. class CurrencyManager
  8. {
  9. const NBP_API_URL = 'http://api.nbp.pl/api/exchangerates/rates/{table}/{code}/';
  10.  
  11. private $em;
  12.  
  13. public function __construct(EntityManagerInterface $em)
  14. {
  15. $this->em = $em;
  16. }
  17. }

Jednak robią w kontrolerze
  1. $this->get(CurrencyManager::class)

Dostaję błąd
Kod
You have requested a non-existent service "AppBundle\Model\CurrencyManager".

services.yml:
Kod
parameters:
    #parameter_name: value

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    AppBundle\:
        resource: '../../src/AppBundle/*'
        exclude: '../../src/AppBundle/{Entity,Repository,Tests}'

    AppBundle\Controller\:
        resource: '../../src/AppBundle/Controller'
        public: true
        tags: ['controller.service_arguments']


Ten post edytował Lirdoner 21.07.2017, 14:02:58
Go to the top of the page
+Quote Post
pyro
post 21.07.2017, 16:03:14
Post #2





Grupa: Zarejestrowani
Postów: 2 148
Pomógł: 230
Dołączył: 26.03.2008

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


To przez to, że przy defaultsach masz:

Kod
public: false


Polecam także całkowicie zrezygnować z autowiring i autoconfigure. Twórcy Symfony w nowej wersji chcieli na siłę coś dodać niby innowacyjnego (co ponoć ma przyśpieszać pracę), ale cały ten pomysł jest po prostu szkaradny od strony architektonicznej i rodzący wiele problemów.

Ten post edytował pyro 21.07.2017, 16:07:13


--------------------
ET LINGUA EIUS LOQUETUR IUDICIUM
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: 13.06.2025 - 22:26