Witam, tworzę stronę internetową, która generuje treść na podstawie pliku xml. Aplikację starałem się oprzeć na architekturze MVC. Poniżej umieszczam kawałek kodu. Uczę się i chciałbym abyście skrytykowali co źle zrobiłem, czy można coś uprościć, czy dobrze rozumiem architekturę. Nie chcę żebyście analizowali skrypt tylko czy są błędy na pierwszy rzut oka.

  1. //Proste zapytania do bazy danych
  2. class PageData
  3. {
  4. function findPage()
  5. {
  6. return $GLOBALS['baza_xml'] -> page;
  7. }
  8.  
  9. function findPageMenu($numberPage, $numberMenu)
  10. {
  11. return $GLOBALS['baza_xml'] -> page[$numberPage] -> menu[$numberMenu];
  12. }
  13.  
  14. function findCountPage() //Funkcja pobiera ilość stron
  15. {
  16. return count($GLOBALS['baza_xml'] -> page);
  17. }
  18.  
  19. function findCountSubPage($numberPage) //Funkcja pobiera ilość podstron
  20. {
  21. return count($GLOBALS['baza_xml'] -> page[$numberPage] -> subpage);
  22. }
  23.  
  24. function findPageText($numberPage, $numberP) //Funkcja pobiera tekst ze strony
  25. {
  26. return $GLOBALS['baza_xml'] -> page[$numberPage] -> conent -> p[$numberP];
  27. }
  28.  
  29. function findSubpageText($numberPage, $numberSubpage, $numberP) //Funkcja pobiera tekst z podstrony
  30. {
  31. return $GLOBALS['baza_xml'] -> page[$numberPage] -> subpage[$numberSubpage] -> conent -> p[$numberP];
  32. }
  33.  
  34. function findPageImg($numberPage, $numberImg) //Funkcja pobiera obrazek ze strony
  35. {
  36. return $GLOBALS['baza_xml'] -> page[$numberPage] -> conent -> img[$numberImg];
  37. }
  38.  
  39. function findSubpageImg($numberPage, $numberSubpage, $numberImg) //Funkcja pobiera obrazek z podstrony
  40. {
  41. return $GLOBALS['baza_xml'] -> page[$numberPage] -> subpage[$numberSubpage] -> conent -> img[$numberImg];
  42. }
  43. }
  44.  
  45. //controller, wszystkie funkcje w klasie zostały stworzone na podstawie zapytań z klasy PageData
  46. class PageController
  47. {
  48. private $a; //Nazwa ścieżki dostępu jest kluczem w bazie "baza_xml".
  49. private $topMenu;
  50. private $bottomMenu;
  51. private $text; //Tekst
  52. private $img; //Zdjęcia
  53. private $title; //tytuł
  54. private $subpage; //temat
  55. private $admission; //wstep
  56. private $countPage; //liczba stron
  57. private $countSubpage; //liczba podstron
  58. private $data; //obiekt klasy DataPage (dane)
  59. private $bottonHeading; //pod nagłówek, tablica
  60. private $topic;
  61.  
  62. public function __construct()
  63. {
  64. $this -> data = new PageData(); //Utworzenie obiektu DataPage
  65. $this -> setA(); //Ustawienie klucza do bazy danych
  66. $this -> setText();
  67. $this -> setTopic();
  68. $this -> setTitle();
  69. $this -> setBottomMenu();
  70. $this -> setTopMenu();
  71. $this -> setAdmission();
  72. }
  73.  
  74. public function setA() //Funkcja ustawia scieżkę dostępu
  75. {
  76. $this -> a = $_SERVER["PHP_SELF"];
  77. $this -> a = substr($this -> a, 1);
  78. }
  79.  
  80. public function getA() //Funkcja zwraca ścieżkę dostępu
  81. {
  82. return $this -> a;
  83. }
  84.  
  85. public function setText() //Funkcja Ustawia tekst
  86. {
  87. for($numberPage = 0; $numberPage < $this -> data -> findCountPage(); ++$numberPage) //Pętla przegląda strony
  88. {
  89. if($this -> data -> findPageA($numberPage) == $this -> getA())
  90. for($numberP = 0; $this -> data -> findPageText($numberPage, $numberP); ++$numberP)
  91. $this -> text[] = $this -> data -> findPageText($numberPage, $numberP);
  92. else
  93. for($numberSubpage = 0; $numberSubpage < $this -> data -> findCountSubPage($numberPage); ++$numberSubpage) //Pętla przegląda podstrony
  94. if($this -> data -> findSubpageA($numberPage, $numberSubpage) == $this -> getA())
  95. for($numberP2 = 0; $this -> data -> findSubpageText($numberPage, $numberSubpage, $numberP2); ++$numberP2)
  96. $this -> text[] = $this -> data -> findSubpageText($numberPage, $numberSubpage, $numberP2);
  97. }
  98. }
  99.  
  100. public function getText()
  101. {
  102. return $this -> text;
  103. }
  104.  
  105. public function setImg()
  106. {
  107. for($numberPage = 0; $numberPage < $this -> data -> findCountPage(); ++$numberPage) //Przeglądamy wszystkie strony
  108. {
  109. if($this -> data -> findPageA($numberPage) == $this -> getA())
  110. for($numberImg = 0; $this -> data -> findPageImg($numberPage, $numberImg); ++$numberImg)
  111. $this -> img[] = $this -> data -> findPageImg($numberPage, $numberImg);
  112. else //pod strona
  113. for($numberSubpage = 0; $numberSubpage < $this -> data -> findCountSubPage($numberPage); ++$numberSubpage)
  114. if($this -> data -> findSubpageA($numberPage, $numberSubpage) == $this -> getA())
  115. for($numberImg = 0; $this -> data -> findSubpageImg($numberPage, $numberSubpage, $numberImg); ++$numberImg)
  116. $this -> img[] = $this -> data -> findSubpageImg($numberPage, $numberSubpage, $numberImg);
  117. }
  118. }
  119.  
  120. public function getImg()
  121. {
  122. return $this -> img;
  123. }
  124.  
  125. }
  126.  
  127. //Klasa odpowiedzialna za wyświetlenie informacji
  128. class PageView
  129. {
  130. private $pageView;
  131.  
  132. public function __construct()
  133. {
  134. $this -> pageView = new PageController();
  135. }
  136.  
  137. public function viewText()
  138. {
  139. foreach($this -> pageView -> getText() as $table)
  140. echo '<p>'.$table.'</p>';
  141. }
  142.  
  143. public function viewImg() //nie dokończone, chyba do usunięcia
  144. {
  145. foreach($this -> pageView -> getImg() as $table)
  146. echo $table;
  147. }
  148. }