Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony2][SF][SF2]Prawidłowa przestrzeń nazw dla klasy dołączanej jako usługa
michau85
post
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
 
Start new topic
Odpowiedzi
michau85
post
Post #2





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 (IMG:style_emoticons/default/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

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 01:48