Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]MVC bez composera
Forum PHP.pl > Forum > Przedszkole
casperii
Witam panowie,
postanowiłem w końcu ogarnąć MVC na przykładzie http://lukasz-socha.pl/php/mvc-w-praktyce-...artykulow-cz-1/ i na dzień dobry dostaje w pysk.
Myślę sobie dobra pozbądźmy się composera

index.php:
  1. require_once 'config.php';
  2. //$loader = include DIR_VENDOR.'autoload.php'; <-- komentuje by nie mieć composera
  3. require_once 'config-router.php';
  4. $router = new \Engine\Router\Router('http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
  5. //var_dump('http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
  6. $router->run();
  7. $file=$router->getFile();
  8. $classController=$router->getClass();
  9. $method=$router->getMethod();
  10. require_once($file);
  11. $obj = new $classController();
  12. $obj->$method();


Niestety tak zedytowany plik daje mi:
Fatal error: Class 'Engine\Router\RouteCollection' not found in /home/konto/public_html/config-router.php on line 2

o to config-router.php
  1. <?php
  2. $collection = new Engine\Router\RouteCollection();
  3.  
  4. $collection->add('category/delete', new \Engine\Router\Route(
  5. HTTP_SERVER.'kategorie/usun/<id>?',
  6. 'file' => DIR_CONTROLLER.'Category.php',
  7. 'method' => 'delete',
  8. 'class' => '\Controller\Category'
  9. ),
  10. 'id' => '\d+'
  11. ),
  12. 'id' => 0
  13. )
  14. ));
  15. $collection->add('category/add', new \Engine\Router\Route(
  16. HTTP_SERVER.'kategorie/dodaj',
  17. 'file' => DIR_CONTROLLER.'Category.php',
  18. 'method' => 'add',
  19. 'class' => '\Controller\Category'
  20. )
  21. ));
  22. $collection->add('category/index', new \Engine\Router\Route(
  23. HTTP_SERVER.'kategorie',
  24. 'file' => DIR_CONTROLLER.'Category.php',
  25. 'method' => 'index',
  26. 'class' => '\Controller\Category'
  27. )
  28. ));
  29. $collection->add('article/delete', new \Engine\Router\Route(
  30. HTTP_SERVER.'artykuly/usun/<id>?',
  31. 'file' => DIR_CONTROLLER.'Article.php',
  32. 'method' => 'delete',
  33. 'class' => '\Controller\Article'
  34. ),
  35. 'id' => '\d+'
  36. ),
  37. 'id' => 0
  38. )
  39. ));
  40. $collection->add('article/one', new \Engine\Router\Route(
  41. HTTP_SERVER.'artykuly/wyswietl/<id>?',
  42. 'file' => DIR_CONTROLLER.'Article.php',
  43. 'method' => 'one',
  44. 'class' => '\Controller\Article'
  45. ),
  46. 'id' => '\d+'
  47. ),
  48. 'id' => 0
  49. )
  50. ));
  51. $collection->add('article/add', new \Engine\Router\Route(
  52. HTTP_SERVER.'artykuly/dodaj',
  53. 'file' => DIR_CONTROLLER.'Article.php',
  54. 'method' => 'add',
  55. 'class' => '\Controller\Article'
  56. )
  57. ));
  58. $collection->add('article/index', new \Engine\Router\Route(
  59. HTTP_SERVER.'artykuly',
  60. 'file' => DIR_CONTROLLER.'Article.php',
  61. 'method' => 'index',
  62. 'class' => '\Controller\Article'
  63. )
  64. ));
  65. $collection->add('homepage', new \Engine\Router\Route(
  66. HTTP_SERVER.'',
  67. 'file' => DIR_CONTROLLER.'Article.php',
  68. 'method' => 'index',
  69. 'class' => '\Controller\Article'
  70. )
  71. ));
  72.  
  73.  
  74. $router = new \Engine\Router\Router($_SERVER['REQUEST_URI'], $collection);
  75.  
  76. ?>


Drugie pytanie czy to:
  1. $model = new \RacyMind\MVCWPraktyce\Model\Category();


oznacza , że plik powinien się znajdować w katalogach RacyMind > MVCWPraktyce ?
Czy coś to zmieni jak pousuwam z kodu \RacyMind\MVCWPraktyce\

Pyton_000
A czemu chcesz się pozbyć composera?
casperii
nie mam dostępu do SSH i chyba bez tego nie zadziała autoload ?
ohm
Oczywiście że zadziała, tylko projekt będziesz musiał z vendorami wrzucić + ewentualnie poprawki w autoloadzie (nie wiem jak teraz, ale kiedyś było część ścieżek na sztywno generowanych)
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.