Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [code] php5 drugie starcie
Forum PHP.pl > Inne > Oceny
acztery
witam, przedstawiam do oceny mój kod klasy która będzie wykorzystana w cms klasie jeszcze brakuje pare rzeczy pisze ją od paru godzinek. widzicie w niej jakieś błędy może ulepszenia ?

  1. <?php
  2. include_once '_i/auto/Documents.php';
  3.  
  4. class Contents extends tblDocuments {
  5.  
  6. public function htmlchars($doc) 
  7. {
  8. // Filter 
  9. $result = isset($doc) ? wordwrap(nl2br(trim($doc))) : null;
  10. return $result;
  11. }
  12.  
  13. public function lstDocuments($_where='')
  14. {
  15. // List in array table documents
  16. $doc = DB_DataObject::factory('documents');
  17. if ($_where <> '') {
  18. $doc->whereAdd("cat = $_where");
  19. }
  20. // Find element in table documents
  21. $doc->find();
  22. while($doc->fetch()) {
  23. $result['data'][] = $doc->toArray();
  24. }
  25. return $result = isset($result) ? $result : null;
  26. }
  27.  
  28.  
  29.  
  30. public function lstCat($_where='')
  31. {
  32. // Connect to table cat
  33. $cat = DB_DataObject::factory('cat');
  34. if ($_where <> '') {
  35. $cat->whereAdd("parent = $_where");
  36. }else{
  37. $cat->whereAdd("parent = 0");
  38. }
  39. // Find element in table cat
  40. $cat->find();
  41. while($cat->fetch()) {
  42. $result['data'][] = $cat->toArray();
  43. }
  44. return $result = isset($result) ? $result : null;
  45. }
  46.  
  47. public function countCat($_where='') 
  48. {
  49. // Count category 
  50.  $cat = DB_DataObject::factory('cat');
  51. if ($_where <> '') {
  52.  $cat->whereAdd("parent = $_where");
  53. }
  54. return $cat->find();
  55.  
  56. }
  57.  
  58. public function countDoc($_where='') 
  59. {
  60. // Count document 
  61.  $doc = DB_DataObject::factory('documents');
  62. if ($_where <> '') {
  63.  $doc->whereAdd("cat = $_where");
  64. }
  65. return $doc->find();
  66.  
  67. }
  68.  
  69. public function addCat($_title, $_desc, $_parent)
  70. {
  71. // Add category
  72. $cat = DB_DataObject::factory('cat');
  73. $cat->Desc=$_desc;
  74. $cat->Title=$_title;
  75. $cat->parent=$_parent;
  76. $cat->insert();
  77. }
  78.  
  79. public function delCat($_id)
  80. {
  81. // Delete category
  82. $cat = DB_DataObject::factory('cat');
  83. $cat->get($_id);
  84. return $cat->delete();
  85.  
  86. }
  87.  
  88. public function delDoc($_id)
  89. {
  90. // Delete document
  91. $doc = DB_DataObject::factory('documents');
  92. $doc->get($_id);
  93. return $doc->delete();
  94. }
  95.  
  96. public function addDoc($_title, $_desc, $_cat)
  97. {
  98. // Add document
  99. $doc = DB_DataObject::factory('documents');
  100. $doc->Desc=Contents::htmlchars($_desc);
  101. $doc->Title=Contents::htmlchars($_title);
  102. $doc->cat=$_cat;
  103. $doc->CreateDate='NOW()';
  104. $doc->insert();
  105. }
  106.  
  107. public function editDoc($_id)
  108. {
  109. // Edit document
  110. }
  111.  
  112. public function getDoc($_where='')
  113. {
  114. // Get in document
  115. $doc = DB_DataObject::factory('documents');
  116. if ($_where <> '') {
  117. $doc->whereAdd("Id = $_where");
  118. }else{
  119. $doc->whereAdd("parent = 0");
  120. }
  121. // Find element in table document
  122. $doc->find();
  123. while($doc->fetch()) {
  124. $result['data'][] = $doc->toArray();
  125. // $result['html']['Desc'] = Contents::htmlchars($result['data']['0']['Desc']);
  126. // $result['html']['Title'] = Contents::htmlchars($result['data']['0']['Title']);
  127. }
  128. return $result = isset($result) ? $result : null;
  129.  
  130. }
  131.  
  132. }
  133. ?>


tak php5 a jest w kodzie cos co by mowiło ze to nie php 5?

a co robi wyciąga z bazy daną treść do cms , treści sa podzielone na kategorie, oczywiscie to cześć kodu i pewnie beda zmiany i duzo dojdzie ale juz chcial bym wiedziec co o tym sadzicie
nospor
dajesz to do oceny, wiec moze bys podal co ta klasa ma robic?
popraw tez tytul. czy ty do oceny oddajesz php5? Nie sądze... smile.gif
bigZbig
Przejrzalem na szybcika:

1. Swoje zmienne nazywasz korzystajac ze wzoru $_cos. Znak pojedynczego podkreslenia stosuje sie umownie dla oznaczenia prywatnego charakteru wlasciwosci lub metody. Wymysl cos innego dla oznaczania swoich zmiennych.

2. Metoda htmlchars jest jak wynika z tresci kodu metody getDoc metoda statyczna. Warto by zatem po slowie public dodac slowo static.

Tak na marginesie to wlasciwie wszystkie funkcje w tej klasie moglbys zadeklarowac jako statyczne i pewnie taki charakter maja miec.
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.