Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony2][SF][SF2]Prawidłowa przestrzeń nazw dla klasy dołączanej jako usługa
michau85
post 21.09.2016, 14:08:55
Post #1





Grupa: Zarejestrowani
Postów: 87
Pomógł: 1
Dołączył: 3.01.2010

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


Hej.
Zarejestrowałem nową klasę jako usługę. Jednak ciągle dostaję taki oto błąd: Attempted to load class "Moj" from namespace "sklep\SklepBundle\Helper".
Did you forget a "use" statement for another namespace? "

Nowa klaa znajduje się w SklepBundle/Helpers/ Moj.php
  1. class Moj{
  2. public $name='jan';
  3.  
  4.  
  5. public function show(){
  6. echo'Moje imie to'. $this->name;
  7.  
  8. }
  9. }
  10.  


Services.yml
  1. services:
  2. moj:
  3. class: sklep\SklepBundle\Helper\Moj




Natomiast kontroler wygląda tak:

  1. use sklep\SklepBundle\Helper\
  2. .
  3. .
  4. .
  5.  
  6. $m=$this->container->get('moj');
  7.  
  8.  

Go to the top of the page
+Quote Post
ohm
post 21.09.2016, 14:18:20
Post #2





Grupa: Zarejestrowani
Postów: 623
Pomógł: 144
Dołączył: 22.12.2010

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


A namespace dodałeś w pliku z klasą Moj?
Go to the top of the page
+Quote Post
michau85
post 21.09.2016, 14:22:39
Post #3





Grupa: Zarejestrowani
Postów: 87
Pomógł: 1
Dołączył: 3.01.2010

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


Coś takiego :
namespace sklep\SklepBundle\Helper\Moj;

Nic się nie zmienia. Dalej en sam błąd.
Go to the top of the page
+Quote Post
nospor
post 21.09.2016, 14:25:35
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




NIe
namespace sklep\SklepBundle\Helper\Moj;

a:
namespace sklep\SklepBundle\Helper;


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
michau85
post 21.09.2016, 14:40:11
Post #5





Grupa: Zarejestrowani
Postów: 87
Pomógł: 1
Dołączył: 3.01.2010

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


Nadal nie działa. sad.gif
Go to the top of the page
+Quote Post
kpt_lucek
post 21.09.2016, 14:48:47
Post #6





Grupa: Zarejestrowani
Postów: 428
Pomógł: 77
Dołączył: 10.07.2011
Skąd: Warszawa

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


Cytat(nospor @ 21.09.2016, 15:25:35 ) *
NIe
namespace sklep\SklepBundle\Helper\Moj;

a:
namespace sklep\SklepBundle\Helper;


Zakładając, że SklepBundle znajduje się bezpośrednio w src to powinno być SklepBundle\Helper.

Nie zmienia to faktu, że echo'Moje imie to'. $this->name; aż krzyczy o pomstę do nieba smile.gif

Pokaż jeszcze config z composer.json


--------------------


Cytat
There is a Bundle for that
Lukas Kahwe Smith - October 31th, 2014
Go to the top of the page
+Quote Post
michau85
post 21.09.2016, 14:53:36
Post #7





Grupa: Zarejestrowani
Postów: 87
Pomógł: 1
Dołączył: 3.01.2010

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


Cytat(kpt_lucek @ 21.09.2016, 15:48:47 ) *
Zakładając, że SklepBundle znajduje się bezpośrednio w src to powinno być SklepBundle\Helper.

Nie zmienia to faktu, że echo'Moje imie to'. $this->name; aż krzyczy o pomstę do nieba smile.gif

Pokaż jeszcze config z composer.json

  1.  
  2. {
  3. "name": "symfony/framework-standard-edition",
  4. "license": "MIT",
  5. "type": "project",
  6. "description": "The \"Symfony Standard Edition\" distribution",
  7. "autoload": {
  8. "psr-4": { "": "src/" },
  9. "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
  10. },
  11. "require": {
  12. "php": ">=5.3.9",
  13. "symfony/symfony": "2.8.*",
  14. "doctrine/orm": "^2.4.8",
  15. "doctrine/doctrine-bundle": "~1.4",
  16. "symfony/swiftmailer-bundle": "~2.3",
  17. "symfony/monolog-bundle": "~2.4",
  18. "sensio/distribution-bundle": "~5.0",
  19. "sensio/framework-extra-bundle": "^3.0.2",
  20. "incenteev/composer-parameter-handler": "~2.0"
  21. },
  22. "require-dev": {
  23. "sensio/generator-bundle": "~3.0",
  24. "symfony/phpunit-bridge": "~2.7"
  25. },
  26. "scripts": {
  27. "post-install-cmd": [
  28. "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
  29. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
  30. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
  31. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
  32. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
  33. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
  34. ],
  35. "post-update-cmd": [
  36. "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
  37. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
  38. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
  39. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
  40. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
  41. "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
  42. ]
  43. },
  44. "config": {
  45. "bin-dir": "bin",
  46. "platform": {
  47. "php": "5.3.9"
  48. }
  49. },
  50. "extra": {
  51. "symfony-app-dir": "app",
  52. "symfony-web-dir": "web",
  53. "symfony-assets-install": "relative",
  54. "incenteev-parameters": {
  55. "file": "app/config/parameters.yml"
  56. },
  57. "branch-alias": {
  58. "dev-master": "2.8-dev"
  59. }
  60. }
  61. }
  62.  
  63.  
Go to the top of the page
+Quote Post
kpt_lucek
post 21.09.2016, 14:55:58
Post #8





Grupa: Zarejestrowani
Postów: 428
Pomógł: 77
Dołączył: 10.07.2011
Skąd: Warszawa

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


No to się nie dziw, zakładam, że SklepBundle znajduje się bezpośrednio w src , w takim razie wywal "sklep\" z namespace'a... Nie wiem skąd go tam masz i po co


--------------------


Cytat
There is a Bundle for that
Lukas Kahwe Smith - October 31th, 2014
Go to the top of the page
+Quote Post
michau85
post 21.09.2016, 15:15:22
Post #9





Grupa: Zarejestrowani
Postów: 87
Pomógł: 1
Dołączył: 3.01.2010

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


Wyrzuciłem sklep i nadal nie działa.
Go to the top of the page
+Quote Post
Fred1485
post 21.09.2016, 15:53:12
Post #10





Grupa: Zarejestrowani
Postów: 361
Pomógł: 22
Dołączył: 10.02.2015

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


Nie wiem czy to coś wniesie do tematu, ale kiedyś miałem podobny problem i dump-autoload pomógł.


--------------------
  1. echo 'I was trying';
  2. die ();
Go to the top of the page
+Quote Post
lukaskolista
post 27.09.2016, 13:54:46
Post #11





Grupa: Zarejestrowani
Postów: 872
Pomógł: 94
Dołączył: 31.03.2010

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


Helper w namespace i Helpers w ścieżce do pliku.
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: 20.06.2025 - 22:02