Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SF2][Symfony][Symfony2]Annotations z routingu nie działa
Crash89
post 26.05.2018, 09:23:09
Post #1





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

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


Stworzyłem nowy projekt na symfony 4 i chciałem skorzystać z adnotacji dla routingu.
Podążając za dokumentacją, niestety po instalacji tychże i próbie uruchomienia jakiegoś routingu z tych adnotacji pojawia się błąd:

Exception thrown when handling an exception (Symfony\Component\Config\Exception\FileLoaderLoadException: Warning: strtoupper() expects parameter 1 to be string, array given in D:\xampp\htdocs\projekt\config/routes\../../src/Controller/ (which is being imported from "D:\xampp\htdocs\projekt\config/routes/annotations.yaml"). Make sure annotations are installed and enabled.)

Czy ktoś miał już taki problem?

Ten post edytował Crash89 26.05.2018, 09:24:11
Go to the top of the page
+Quote Post
Pyton_000
post 26.05.2018, 21:39:36
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Pokaż klasę z annotacjami.
Go to the top of the page
+Quote Post
Crash89
post 27.05.2018, 10:25:19
Post #3





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

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


Cytat(Pyton_000 @ 26.05.2018, 22:39:36 ) *
Pokaż klasę z annotacjami.


  1. namespace App\Controller;
  2.  
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  7.  
  8. /**
  9.  * Class LuckyController
  10.  * @package App\Controller
  11.  */
  12. class LuckyController extends Controller
  13. {
  14. /**
  15.   * @Route("/")
  16.   */
  17. public function number()
  18. {
  19.  
  20. $number = 10;
  21. return new Response(
  22. '<html><body>Lucky number: '.$number.'</body></html>'
  23. );
  24. }
  25.  
  26. /**
  27.  * @Route("/test")
  28.  * @Method({"GET"},{"POST"})
  29.  */
  30. public function test()
  31. {
  32.  
  33. return new Response(
  34. '<html><body>test</body></html>'
  35. );
  36.  
  37. }
  38. }


annotations.yml
  1. controllers:
  2. resource: ../../src/Controller/
  3. type: annotation


Kiedy zakomentuje plik annotations.yml, to działają routingi z pliku routes.yaml
Ale chciałbym pracować na adnotacjach.

Ten post edytował Crash89 27.05.2018, 10:28:05
Go to the top of the page
+Quote Post
Pyton_000
post 27.05.2018, 11:21:29
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Zamień tą drugą annotację na

Kod
@Route("/test", methods={"POST","GET"})


i jako use `Sensio\Bundle\FrameworkExtraBundle\Configuration\Route`

[editet]
i nie
Kod
* @Method({"GET"},{"POST"})

a
Kod
* @Method({"GET", "POST"})


https://symfony.com/doc/current/bundles/Sen...ndle/index.html

Ten post edytował Pyton_000 27.05.2018, 11:25:16
Go to the top of the page
+Quote Post
Crash89
post 27.05.2018, 11:45:49
Post #5





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

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


Cytat(Pyton_000 @ 27.05.2018, 12:21:29 ) *
Zamień tą drugą annotację na

Kod
@Route("/test", methods={"POST","GET"})


i jako use `Sensio\Bundle\FrameworkExtraBundle\Configuration\Route`

[editet]
i nie
Kod
* @Method({"GET"},{"POST"})

a
Kod
* @Method({"GET", "POST"})


https://symfony.com/doc/current/bundles/Sen...ndle/index.html


dalej jest ten sam błąd.
A w którym pliku jest ta konfiguracja?
https://symfony.com/doc/current/bundles/Sen...l#configuration

Go to the top of the page
+Quote Post
Pyton_000
post 27.05.2018, 11:53:01
Post #6





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


wywaliłeś cache?
Go to the top of the page
+Quote Post
Crash89
post 27.05.2018, 11:54:32
Post #7





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

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


Cytat(Pyton_000 @ 27.05.2018, 12:53:01 ) *
wywaliłeś cache?


Tak
Go to the top of the page
+Quote Post
ohm
post 27.05.2018, 12:00:24
Post #8





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

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


Nie za daleko wyjechałeś z katalogiem z tymi annotacjami?
https://github.com/symfony/demo/blob/master...nnotations.yaml
Go to the top of the page
+Quote Post
Pyton_000
post 27.05.2018, 12:00:30
Post #9





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


pokaż klasę po zmianach
Go to the top of the page
+Quote Post
Crash89
post 27.05.2018, 12:08:43
Post #10





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

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


Cytat(ohm @ 27.05.2018, 13:00:24 ) *
Nie za daleko wyjechałeś z katalogiem z tymi annotacjami?
https://github.com/symfony/demo/blob/master...nnotations.yaml


Chyba nie, ta zmiana nic nie zmienia.
Tak mi framework stworzył ten plik.


Cytat(Pyton_000 @ 27.05.2018, 13:00:30 ) *
pokaż klasę po zmianach


  1.  
  2. <?php
  3.  
  4. namespace App\Controller;
  5.  
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. //use Symfony\Component\Routing\Annotation\Route;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  11.  
  12. /**
  13.  * Class LuckyController
  14.  * @package App\Controller
  15.  */
  16. class LuckyController extends Controller
  17. {
  18. /**
  19.   * @Route("/")
  20.   */
  21. public function number()
  22. {
  23.  
  24. $number = 10;
  25. return new Response(
  26. '<html><body>Lucky number: '.$number.'</body></html>'
  27. );
  28. }
  29.  
  30. /**
  31.  * @Route("/test", methods={"POST","GET"})
  32.  *
  33.  */
  34. public function test()
  35. {
  36.  
  37. return new Response(
  38. '<html><body>test</body></html>'
  39. );
  40.  
  41. }
  42. }


cały czas odpalam metode number.

Ten post edytował Crash89 27.05.2018, 12:11:59
Go to the top of the page
+Quote Post
Pyton_000
post 27.05.2018, 12:11:04
Post #11





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


nie no u mnie działa normalnie.

zainstalowałeś annotacje?

Kod
composer require annotations
Go to the top of the page
+Quote Post
Crash89
post 27.05.2018, 12:13:29
Post #12





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

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


Cytat(Pyton_000 @ 27.05.2018, 13:11:04 ) *
nie no u mnie działa normalnie.

zainstalowałeś annotacje?

Kod
composer require annotations


Tak,
a pobierałeś najnowszą wersje do instalacji przez
  1. composer create-project symfony/website-skeleton my-project

?

Może coś w najnowszej wersji zmieniono i teraz nie działa.


Ten post edytował Crash89 27.05.2018, 12:14:36
Go to the top of the page
+Quote Post
Pyton_000
post 27.05.2018, 12:20:38
Post #13





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Z ciekawości zainstalowałem jeszcze raz twoim sposobem i działa. Odpalam serwer przez

Kod
php -S 127.0.0.1:8000 -t public
Go to the top of the page
+Quote Post
Crash89
post 27.05.2018, 12:22:06
Post #14





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

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


Cytat(Pyton_000 @ 27.05.2018, 13:20:38 ) *
Z ciekawości zainstalowałem jeszcze raz twoim sposobem i działa. Odpalam serwer przez

Kod
php -S 127.0.0.1:8000 -t public


Używam xamppa, spróbuje jeszcze raz założyć nowy projekt.

Edit:

Postawiłem nowy projekt i działa, dzięki za pomoc.

Ten post edytował Crash89 27.05.2018, 12:35:26
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 - 22:15